Re: Randomly outputting an array
- From: Logan Shaw <lshaw-usenet@xxxxxxxxxxxxx>
- Date: Sun, 16 Jul 2006 15:53:20 GMT
Ico wrote:
Ico <usenet@xxxxxxx> wrote:
Is N times swapping two elements considered enough to truly 'randomize'
an array ?
That was a stupid question, please ignore me...
Actually, it's not a stupid question. It's a very good question.
The answer is definitely "no".
It turns out, there are lots of ways of shuffling an array that
will not[1] really shuffle it properly. The key is getting every
element to have an equal chance of popping up in any other location.
That may be a little harder than it looks, or at least a little
easier to screw up than it looks.
Unfortunately, I only have a second to write this post, but I remember
taking a probability course in college and, while I was taking it,
looking into this exact issue. I looked at the Fisher-Yates algorithm
for shuffling an array and I realized why it's structured exactly the
way it is and why it has to be that way.
I wish I had more time to delve into this right now, and that my
knowledge of probability were still fresh, but I believe it is
important, if you care about having a truly random arrangement of
array elements afterwards (rather than having slightly higher odds
of elements at the beginning ending up at the end or something)
to use the right algorithm.
- Logan
[1] even assuming a random number generator that generates truly
random numbers.
.
- Follow-Ups:
- Re: Randomly outputting an array
- From: toby
- Re: Randomly outputting an array
- From: Arthur J. O'Dwyer
- Re: Randomly outputting an array
- 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
- Randomly outputting an array
- Prev by Date: Re: Randomly outputting an array
- 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
|