S
Stefano Crocco
I've just stumbled upon a strange behaviour of Array#choice (using ruby 1.8.7-
p72). As far I understand, an_array.choice should be (almost) the same as
an_array[rand(an_array.size)]. Thus, the two following pieces of code should
be equivalent
a = [1, 2, 3, 4]
p 10.times.map{a.choice}.join
p 10.times.map{a[rand(a.size)].join}
However, this doesn't seem to be the case. In particular, something like:
ruby -e 'a = [1, 2, 3, 4]; p 10.times.map{a.choice}.join'
always give the same result, while
p72). As far I understand, an_array.choice should be (almost) the same as
an_array[rand(an_array.size)]. Thus, the two following pieces of code should
be equivalent
a = [1, 2, 3, 4]
p 10.times.map{a.choice}.join
p 10.times.map{a[rand(a.size)].join}
However, this doesn't seem to be the case. In particular, something like:
ruby -e 'a = [1, 2, 3, 4]; p 10.times.map{a.choice}.join'
always give the same result, while