in reply to Re^2: Generating 0 .. N Randomly and Efficiently
in thread Generating 0 .. N Randomly and Efficiently
Anyway, though you do take care to make sure every loop finds at least one item, you will not get a nice even distribution. Let me give an example.
Suppose that your $N is 20, and by some weird coincidence, the numbers 1 .. 10 have already been picked, and nothing else. For your next pick, the numbers 12 to 20 all have 1 chance in 21 of being picked. So do the numbers 0 and 11. But if the drawn number is between 1 and 10 (about 10 chances in 21, that is almost 50%), your system will promote it to either 0 or 11...
Net result: there's 12 chances in 21, that is over 50%, that the next number picked, will be either 0 or 11.
So yes, this way, you'll tend to get clustered results, instead of a nicely spread, speckled, outcome.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Generating 0 .. N Randomly and Efficiently
by Limbic~Region (Chancellor) on Oct 19, 2004 at 18:56 UTC |