in reply to Re: Check randomly generated numbers have not been used before (shuffle)
in thread Check randomly generated numbers have not been used before
Actually shuffling 1..1e7 takes an eternity, but shuffling 1..1000 for 10000 times only takes seconds and is deterministic depending on the seed of srand .
So a second rand to chose one of these 10000 arrays and shift one element should be easy, fast, deterministic and produce quite good distributed results.
The mileage of the OP may vary. :)
The real complication of this whole approach of "try again another random number if already taken" idea, cause this will slow down considerably after a while if millions of random numbers need to be tried out.
Thats why shuffling is the far better approach.
Cheers Rolf
(addicted to the Perl Programming Language)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Check randomly generated numbers have not been used before (knowledge vs. expertise)
by BrowserUk (Patriarch) on Jun 22, 2014 at 09:24 UTC | |
by Anonymous Monk on Jun 22, 2014 at 13:33 UTC |