lecture code viewer
downloads
Code
Generating Randomness
Generating Randomness
Martin Krzywinski
#!/usr/local/bin/perl -w
use strict;
use lib "/home/martink/export/extern/perl/lib/site_perl/5.005";
use Math::BaseCalc;
use Math::VecStat qw(average);
use constant PI => 3.1415926535897932;
$\="\n";
$,=" ";
my @bases = (3,5);
my $bobj;
for my $b (@bases) {
$bobj->{$b} = Math::BaseCalc->new(digits=>[0..$b-1]);
}
for my $j (1..7) {
my @pi;
my $num = 10**$j;
for my $iter (0..0) {
my @h = map { [rand(),rand()] } (0..$num-1);
my $c;
for my $h (@h) {
my ($x,$y) = @$h;
my $d = (0.5-$x)*(0.5-$x) + (0.5-$y)*(0.5-$y);
my $dt = int ($d < 0.25);
$c ++ if $dt;
}
my $pi = 4*$c/$num;
push(@pi,$pi);
}
print "value",$num,average(@pi);
print "diff",$num,abs(average(@pi) - PI)/PI;
}
sub makehaltonpoints {
my $n = shift;
my @h;
for my $i (0..$n-1) {
my @v;
for my $b (@bases) {
my $n = $bobj->{$b}->to_base($i);
my $nr = "0.".join("", reverse split("",$n));
push(@v,$bobj->{$b}->from_base($nr));
}
push(@h,\@v);
}
return @h;
}
|
1 |
Generating Randomness |
4.1.2.2.1
4.1.2.2.1.c1 |
brownnoise.wav
|
Martin Krzywinski
|
code
4.1.2.2.1.c2 |
devrandom
|
Martin Krzywinski
|
code
4.1.2.2.1.c3 |
drophaltonrice
|
Martin Krzywinski
|
code
4.1.2.2.1.c4 |
droprice
|
Martin Krzywinski
|
code
4.1.2.2.1.c5 |
halton
|
Martin Krzywinski
|
code
4.1.2.2.1.c6 |
halton.11.13.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c7 |
halton.3.5.1000.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c8 |
halton.3.5.10000.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c9 |
halton.3.5.200.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c10 |
halton.3.5.2000.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c11 |
halton.3.5.400.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c12 |
halton.3.5.4000.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c13 |
halton.3.5.600.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c14 |
halton.3.5.800.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c15 |
halton.3.5.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c16 |
halton.5.7.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c17 |
halton.7.17.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c18 |
halton.new.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c19 |
haltonrice.diff.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c20 |
haltonrice.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c21 |
pinknoise.wav
|
Martin Krzywinski
|
code
4.1.2.2.1.c22 |
prng
|
Martin Krzywinski
|
code
4.1.2.2.1.c23 |
prng.1.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c24 |
prng.2.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c25 |
prng.3.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c26 |
randbase
|
Martin Krzywinski
|
code
4.1.2.2.1.c27 |
randrice.diff.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c28 |
randrice.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c29 |
randstring
|
Martin Krzywinski
|
code
4.1.2.2.1.c30 |
randtests
|
Martin Krzywinski
|
code
4.1.2.2.1.c31 |
rice.diff.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c32 |
rice.results.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c33 |
rice.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c34 |
rice.value.txt
|
Martin Krzywinski
|
code
4.1.2.2.1.c35 |
shake
|
Martin Krzywinski
|
code
4.1.2.2.1.c36 |
trulyrandom
|
Martin Krzywinski
|
code
4.1.2.2.1.c37 |
whitenoise.wav
|
Martin Krzywinski
|
code
4.1.2.2.1.a1 |
Generating Randomness
|
Martin Krzywinski
|
pdf
4.1.2.2.1.p1 |
Generating Randomness
|
Martin Krzywinski
|
ppt
4.1.2.2.1.s1 |
Generating Randomness
|
Martin Krzywinski
|
slides
|