Re: Randomly outputting an array
- From: Gerry Quinn <gerryq@xxxxxxxxxxxxxxxxxxx>
- Date: Mon, 17 Jul 2006 12:06:54 +0100
In article <Pine.LNX.4.60-041.0607161411410.6121
@unix43.andrew.cmu.edu>, ajonospam@xxxxxxxxxxxxxx says...
Picking N pairs uniformly at random and swapping them will definitely
not shuffle the array, since there are (N^2)^N = N^(2N) ways to pick
N pairs, and N! ways to shuffle the array, and N^(2N) is generally not
a multiple of N!.
However, if you carefully pick those N pairs so that the first swap
swaps a random element into position 1, the second swap swaps a random
element /from those that remain/ into position 2, and so on, then that's
the "52-card pickup" algorithm, and it works fine. It's all in /which/
N pairs you swap.
You're right, my method doesn't work. I can't quite see what is
logically wrong with it, but if it makes n^n possible results, n! isn't
going to divide exactly into it.
- Gerry Quinn
.
- References:
- Randomly outputting an array
- From: ryanarossi@xxxxxxxxx
- Re: Randomly outputting an array
- From: Richard Heathfield
- Re: Randomly outputting an array
- From: Ico
- Re: Randomly outputting an array
- From: Ico
- Re: Randomly outputting an array
- From: Logan Shaw
- Re: Randomly outputting an array
- From: Arthur J. O'Dwyer
- Randomly outputting an array
- Prev by Date: Re: Dynamically Creating Variables in C#
- Next by Date: Re: What language for mathematical applications?
- Previous by thread: Re: Randomly outputting an array
- Next by thread: Re: Randomly outputting an array
- Index(es):
Relevant Pages
|