SRoulette (OP)
|
|
March 01, 2013, 02:34:03 PM |
|
Updates finished For those that are interested, here is a simple simulator to demonstrate the fairness of our new RNG. rng_sim.pl#!/usr/bin/perl -w
use strict; use warnings; use Digest::SHA qw(hmac_sha512_hex); use Math::Random::MT;
my $range = $ARGV[0]; our $secret = rand(); my $r = 0; my %hash = (); my $cc = 1; my $c = 1;
while(1) { $r = &get_result(rand(), $range); $hash{$r}++; $c++; $cc++;
if($cc >= 100000) { $cc = 0; my $t = 0; print "\ncount at $c\n"; while($t <= $range) { if(defined $hash{$t}) { my $s = sprintf("%.4f", ( $hash{$t} / $c ) * 100 ); print "Result: $t, Count: $hash{$t}, Perecent: $s%\n"; } $t++; } } }
exit 0;
sub get_result { my $tx = shift; my $range = shift; my $seed = Digest::SHA::hmac_sha512_hex($tx, $main::secret); $seed =~ s/^(.{8}).*$/$1/; $seed = hex($seed) + 0; my $gen = Math::Random::MT->new($seed); my $number = int($gen->rand($range)+1); return $number; }
The above code is released under the freebsd license, you are welcome to reuse this method in your own projects and we hope to see any improvements you may come up with.
Here is a sample run where we are testing roulette. Note this program does not exit, it keeps building statistics against the original secret. satoshi@KVMSERVER:~/super_satoshi/extra$ perl number_distribution_mersenne.pl 10
count at 100000 Result: 1, Count: 10004, Perecent: 10.0040% Result: 2, Count: 9973, Perecent: 9.9730% Result: 3, Count: 10105, Perecent: 10.1050% Result: 4, Count: 9878, Perecent: 9.8780% Result: 5, Count: 10129, Perecent: 10.1290% Result: 6, Count: 10113, Perecent: 10.1130% Result: 7, Count: 9975, Perecent: 9.9750% Result: 8, Count: 9988, Perecent: 9.9880% Result: 9, Count: 9911, Perecent: 9.9110% Result: 10, Count: 9923, Perecent: 9.9230%
count at 200000 Result: 1, Count: 20130, Perecent: 10.0650% Result: 2, Count: 20054, Perecent: 10.0270% Result: 3, Count: 20025, Perecent: 10.0125% Result: 4, Count: 19851, Perecent: 9.9255% Result: 5, Count: 19943, Perecent: 9.9715% Result: 6, Count: 20089, Perecent: 10.0445% Result: 7, Count: 20057, Perecent: 10.0285% Result: 8, Count: 19903, Perecent: 9.9515% Result: 9, Count: 20162, Perecent: 10.0810% Result: 10, Count: 19785, Perecent: 9.8925%
count at 300000 Result: 1, Count: 30148, Perecent: 10.0493% Result: 2, Count: 30081, Perecent: 10.0270% Result: 3, Count: 30078, Perecent: 10.0260% Result: 4, Count: 29776, Perecent: 9.9253% Result: 5, Count: 30014, Perecent: 10.0047% Result: 6, Count: 30091, Perecent: 10.0303% Result: 7, Count: 29977, Perecent: 9.9923% Result: 8, Count: 29967, Perecent: 9.9890% Result: 9, Count: 30212, Perecent: 10.0707% Result: 10, Count: 29655, Perecent: 9.8850%
count at 400000 Result: 1, Count: 40256, Perecent: 10.0640% Result: 2, Count: 39983, Perecent: 9.9958% Result: 3, Count: 40089, Perecent: 10.0223% Result: 4, Count: 39957, Perecent: 9.9893% Result: 5, Count: 39915, Perecent: 9.9787% Result: 6, Count: 40054, Perecent: 10.0135% Result: 7, Count: 39931, Perecent: 9.9827% Result: 8, Count: 40027, Perecent: 10.0068% Result: 9, Count: 40198, Perecent: 10.0495% Result: 10, Count: 39589, Perecent: 9.8972%
count at 500000 Result: 1, Count: 50231, Perecent: 10.0462% Result: 2, Count: 50015, Perecent: 10.0030% Result: 3, Count: 50134, Perecent: 10.0268% Result: 4, Count: 49826, Perecent: 9.9652% Result: 5, Count: 50056, Perecent: 10.0112% Result: 6, Count: 50066, Perecent: 10.0132% Result: 7, Count: 49844, Perecent: 9.9688% Result: 8, Count: 50029, Perecent: 10.0058% Result: 9, Count: 50249, Perecent: 10.0498% Result: 10, Count: 49549, Perecent: 9.9098% ^C satoshi@KVMSERVER:~/super_satoshi/extra$ Note how the results trend towards smoother number distribution each report. I will start the sim up again and leave it running several hours then reply back again with the last report.
|