Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!


By: kberg on Feb 16th, 2012  |  syntax: None  |  size: 0.58 KB  |  views: 153  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print  |  QR code  |  clone
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.
  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.
  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?
clone this paste RAW Paste Data