[racket-dev] How about adding this simple list-shuffling procedure to racket?
I think that if random doesn't pick the same number twice you're
guaranteed to be independent of the sorting algorithm, at least.
Robby
On Thu, Nov 11, 2010 at 11:18 AM, Neil Toronto <neil.toronto at gmail.com> wrote:
> Eric Hanchrow wrote:
>>
>> I find myself using this all the time; it seems it'd be handy to have
>> built in.
>>
>> (define (shuffled list)
>> (sort list < #:key (lambda (_) (random)) #:cache-keys? #t))
>
> Is the distribution of shuffled lists uniform? That'd be hard to analyze,
> since it would depend on the sorting algorithm. I would guess it's not.
>
> (Don't worry if you didn't catch this yourself. It's not exactly
> straightforward.)
>
> If you want an "unbiased" shuffle, see
>
> http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
>
> Neil T
> _________________________________________________
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/dev
>