Re: Random reordering of a list
From: Top Spin (ToppSpin_at_hotmail.com)
Date: 12/05/04
- Next message: K Yee: "properties of a "double" quadratic form?"
- Previous message: Luis A. Rodriguez: "Re: don't understand computer experiment of random process?"
- In reply to: Ross Clement: "Re: Random reordering of a list"
- Next in thread: jim clark: "Re: Random reordering of a list"
- Reply: jim clark: "Re: Random reordering of a list"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 05 Dec 2004 07:51:29 -0800
On 5 Dec 2004 03:58:59 -0800, clemenr@wmin.ac.uk (Ross Clement) wrote:
>Top Spin <ToppSpin@hotmail.com> wrote in message news:<j7f5r0p9dvj502uclnhfq59dqhhvesg3g6@4ax.com>...
>> On Tue, 9 Nov 2004 12:33:05 +1300, "Jeff Miller" <nobody@nowhere.com>
>> wrote:
>> >No, that isn't quite right, intuitive as it appears. To convince yourself
>> >that it isn't right, consider n=3. There are 6 possible orderings, and
>> >you want to make them all equally likely. Now look at
>> >your algorithm: there are 3*3*3=27 equally likely ways it can proceed
>> >(determined by the 3 independent outcomes of the "random" statement).
>> >But 27 isn't evenly divisible by 6, so the 6 possible orderings cannot be
>> >equally likely. Counterintuitive, but evidently true.
>>
>> When I first read your reply, it looked plausible to me. I have since
>> coded it up and run it. It appears to generate an even distribution of
>> the 6 possible permutations.
>
>There are three ways of choosing the first element. For each of these
>choices, there are two ways of choosing the next element. There is
>then one number remaining, so it must be chosen. Hence the number of
>possible ways that the algorithm can proceed is six.
Yes, that's is how the possible permutations are calculated, but
that's not how either algorithm operates.
My algorithm visits each element in the array in ascending order and
swaps it with a random element in the entire array. I have simulated
this algorithm with a few billion iterations and the distribution
looks even.
Jim Clark's algorithm also visits each element in the array except the
first, but in reverse order, and he only swaps it with one of the
unvisited elements. I was concerned that he doesn't explicitly visit
the 1st element, but I also simulated this algorithm and the
distribution also looks even.
>Whether we're choosing the last element in the array, or the first
>element, makes no difference that I can see, apart from the effects
>due to the pseudo-random number generator not being
Yes, I can't see that it matters which direction you go.
-- Email: Usenet-20031220 at spamex.com (11/09/04)
- Next message: K Yee: "properties of a "double" quadratic form?"
- Previous message: Luis A. Rodriguez: "Re: don't understand computer experiment of random process?"
- In reply to: Ross Clement: "Re: Random reordering of a list"
- Next in thread: jim clark: "Re: Random reordering of a list"
- Reply: jim clark: "Re: Random reordering of a list"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|