From: x on
Haris Bogdanovi� <fbogdanovic(a)xnet.hr> wrote in news:i343g1$gc1$1
@gregory.bnet.hr:

> How to randomize a list ?

One way would be to shuffle it like playing cards. Divide the list in two
then pop from each at random to make a new list. Most lisps work with
lists much faster than other data structures because they recycle cons
cells. How many times you have to shuffle is proportional to the log of
the length of the list. A deck of playing cards should be shuffled more
than five times because each shuffle is not perfectly random because clumsy
fingers let several cards move together. But less than five times because
card players don't care if it's perfectly random.

It would be interesting to time it vs other methods, for different lengths
of lists.
From: josephoswald+gg on
On Aug 1, 9:18 pm, w_a_x_man <w_a_x_...(a)yahoo.com> wrote:
> On Aug 1, 10:22 am, Haris Bogdanoviæ <fbogdano...(a)xnet.hr> wrote:
>
> > Hi.
>
> > How to randomize a list ?
>
> > Thanks
>
> (1..9).sort_by{ rand }
> [7, 1, 3, 5, 9, 2, 6, 8, 4]

Even in Ruby this approach is buggy. It does not select each
permutation with equal likelihood.

But hey, if you can't pay attention to the name of the newsgroup, why
would you pay attention to other matters of correctness?

http://eigenclass.org/hiki/sort_by+rand+is+biased
First  |  Prev  | 
Pages: 1 2 3
Prev: ANUSHKA HOT PICTURES
Next: TextMate Common Lisp Bundle