in reply to •Re: Select three random numbers between 1..10
in thread Select three random numbers between 1..10
is less efficient thanif ($swapper < $#population) { $population[$swapper] = $population[-1]; }
Sure, the if statement prevents a needless assignment, but the expected number of needless assignments is$population[$swapper] = $population[-1];
Σi=0$n 1/(@population - i)which, while unbounded, grows very very slowly if the array to sample grows. OTOH, the number of compares done is linear with the size of the sample taken.
Abigail
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Re: Select three random numbers between 1..10
by merlyn (Sage) on Mar 17, 2004 at 02:19 UTC |