Advertisement
kberg

Untitled

Feb 16th, 2012
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. The algorithm iterates n times. Each iteration, m, selects a random index from 0-m-1, pulls it from the source array, and pushes it to the destination array. The array is now size m-1. When the array size is 1, the random number generator selects a value from 0-0.
  2.  
  3. So, when m=1, it selects one possible value
  4. m=2, selects one of two possible values.
  5. m=3, selects one of three possible values.
  6. m=n, selects one of n values.
  7.  
  8. Now I wave my hands a little to demonstrate my lack of past math skills, and presto! the use of the randomizer results in one of n! possible outcomes. How's that?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement