Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: Random 1-1 mapping

by blokhead (Monsignor)
on May 28, 2006 at 21:26 UTC ( [id://552217] : note . print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    f(x) = (a*x + b) % m
    
  2. or download this
    sub gcd { $_[1] ? gcd($_[1], $_[0] % $_[1]) : $_[0] }
    
    ...
        my @result = map shuffle($seed, 15, $_), 0 .. 14;
        print "seed=$seed ==> @result\n";
    }
    
  3. or download this
    seed=1 ==> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
    seed=2 ==> 0 2 4 6 8 10 12 14 1 3 5 7 9 11 13
    ...
    seed=8 ==> 0 8 1 9 2 10 3 11 4 12 5 13 6 14 7
    seed=9 ==> 1 9 2 10 3 11 4 12 5 13 6 14 7 0 8
    seed=10 ==> 2 10 3 11 4 12 5 13 6 14 7 0 8 1 9