Help for this page

Select Code to Download


  1. or download this
    -- To shuffle an array a of n elements (indices 0..n-1):
    for i from 0 to n-2 do
         j <- random integer such that i <= j < n
         exchange a[i] and a[j]
    
  2. or download this
    $n = scalar(@aliased);
    $a = $_ + rand @aliased - $_ # original code
    ...
       = random integer such that i <= j <= i+$n-i-1
       = random integer such that i <= j <= $n-1
       = random integer such that i <= j <  $n
    
  3. or download this
    for 0 .. $#aliased {
       $a = $_ + rand @aliased - $_;
    ...
       $aliased[ $_ ] = $aliased[ $a ],
       $aliased[ $a ] = $b
    }
    
  4. or download this
    for i from 0 to n-1 do
       j <- random integer such that i <= j < n
       exchange a[i] and a[j]
    
  5. or download this
    #!/usr/bin/env perl
    
    ...
            my ($a, $b) = @_;
            return 100 - 100 * $a / $b
    }
    
  6. or download this
    #!/usr/bin/env perl
    
    ...
            my ($a, $b) = @_;
            return 100 - 100 * $a / $b
    }
    
  7. or download this
    #!/usr/bin/env perl
    
    ...
            my ($a, $b) = @_;
            return 100 - 100 * $a / $b
    }
    
  8. or download this
    ./random_walk_test.pl : done 10000000 trials with 10 bins, here is a s
    +ummary:
    ./random_walk_test.pl : RandomWalk test : Math::Random::MT's rand() wi
    +th mean %diff from expected to be 0.022 %
    ...
    
    ./transition_matrix_test.pl : best results for transition matrix test 
    +: Perl's rand() with mean %diff from expected count to be 1.796 %
    ./transition_matrix_test.pl : end.