Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Random 1-1 mapping

by tomazos (Deacon)
on May 28, 2006 at 18:54 UTC ( [id://552204] : note . print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    $result = ($prime_number * $input + $seed) % $max;
    
  2. or download this
    shuffle(5,10,0) == (7 * 0 + 5) % 10 == 5 % 10 == 5
    shuffle(5,10,1) == (7 * 1 + 5) % 10 == 12 % 10 == 2
    ...
    shuffle(5,10,7) == (7 * 7 + 5) % 10 == 54 % 10 == 4
    shuffle(5,10,8) == (7 * 8 + 5) % 10 == 61 % 10 == 1
    shuffle(5,10,9) == (7 * 9 + 5) % 10 == 68 % 10 == 8