Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/markov-reloaded.rb

Instance Method Summary collapse

Instance Method Details

#pickRand(rng) ⇒ Object



34
35
36
37
# File 'lib/markov-reloaded.rb', line 34

def pickRand(rng)
	r = rng.rand(length)
	self[r]
end

#toMarkov(order) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/markov-reloaded.rb', line 38

def toMarkov(order)
	data = Hash.new(:Error)
	array = self
	for i in 0..array.length-1-order
		el = array[i..i+order-1]
		if data.include? el
			data[el].push array[i+order]# unless i+order+1 == array.length
		else
			data[el] = [array[i+order]]# unless i+order+1 == array.length
		end
	end
	Markov.new(data, order)
end