Author

Topic: Satoshi Roulette - New RNG (Read 1325 times)

sr. member
Activity: 364
Merit: 252
March 02, 2013, 09:21:41 AM
#10
What were the results for the previous RNG setup?

There was a slight bias against some number on games with ranges that did not divided evenly by 65536. Thanks to use of the mersenne twister algo this issue is now resolved.
If you are interested we can run another round of simulations using the same application but applying our old RNG routine.
member
Activity: 84
Merit: 10
Weighted companion cube
March 02, 2013, 01:19:47 AM
#9
What were the results for the previous RNG setup?
sr. member
Activity: 364
Merit: 252
March 02, 2013, 12:07:18 AM
#8
Code:
count at 1588000000
Result: 1, Count: 529274368, Perecent: 33.3296%
Result: 2, Count: 529388054, Perecent: 33.3368%
Result: 3, Count: 529337577, Perecent: 33.3336%

Nearly Cheesy anyway at 1'588'000'000 / ~1.6 billion rounds simulated its demonstration enough that its fair.
sr. member
Activity: 364
Merit: 252
March 01, 2013, 11:12:53 AM
#7
88200000 simulated rounds Using a range of 3 (eg rock paper scissors):
Code:
count at 88200000
Result: 1, Count: 29394593, Perecent: 33.3272%
Result: 2, Count: 29402965, Perecent: 33.3367%
Result: 3, Count: 29402441, Perecent: 33.3361%

The distribution is quite nice, I shall leave the sim grinding over night and see if we cant get it to 33.333x
sr. member
Activity: 364
Merit: 252
March 01, 2013, 09:34:03 AM
#6
Updates finished  Grin

For those that are interested, here is a simple simulator to demonstrate the fairness of our new RNG.


rng_sim.pl
Code:
#!/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.

Code:
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.
sr. member
Activity: 364
Merit: 252
March 01, 2013, 09:22:31 AM
#5
Bitcoin Checkpoint Secret:
Code:
6ac5ddf0c1f585c6901c6e20cabbcdbe16169d918c2fd40b306002fe0a34aa262382208dffec352bb34027382a2707749ed64e2cb7a8a1cc0f1ec8f013b11324
sr. member
Activity: 364
Merit: 252
March 01, 2013, 09:20:22 AM
#4
Litecoin Checkpoint Secret:
Code:
2aa632935450f425b90e9c7b0e17cd806adc43de5c48bfebbebfce75426a463d9af6ea69f464d9be0fdce7bfee8ac2d1fd57e26fbfae7e8d5885b7a0523dd0c6
sr. member
Activity: 364
Merit: 252
March 01, 2013, 09:17:45 AM
#3
PPCoin Checkpoint Secret:
Code:
efbc102277fb318a15dc27d73b4c78713fb4f0930c597b5895e34c20c5e4e9a612220140ae33ebcd1502b3e52b757158da60f7a8ef76926ec2f1ce8ca4c15cad
sr. member
Activity: 364
Merit: 252
March 01, 2013, 09:14:42 AM
#2
TERRACOIN Checkpoint secret:
Code:
32085665c5cb5a9e3897149a827ce441ea012f8ac7d0a56fdfbe3ed2bb22ba06d5c2a11b9f898de8948636bc0e6561ad374bda7d21933bce59dadf2bd5b3d1da
sr. member
Activity: 364
Merit: 252
March 01, 2013, 09:09:29 AM
#1
We have upgraded our random number generator to be fairer and ensure an even distribution.
We now use a combination of hmac sha512 and mersenne twister.

The new rng will be used at the next secret change, an out of schedule secret change will be forced shortly.
To ensure our honestly the last secret used for each commodity will be record in a reply message below which we will not edit, this will serve as the RNG upgrade checkpoint.

to validate game results, use our new perl script which will also be uploaded to our web server and referenced in our FAQ shortly.


bet_verify2.pl
Code:
#!/usr/bin/perl -w
# bet_verify2.pl by codemonkey :3

use strict;
use warnings;

use Digest::SHA qw(hmac_sha512_hex);
use Math::Random::MT;

if(!$ARGV[0] || $ARGV[0] eq "--help" || $ARGV[0] eq "-h" || $ARGV[0] eq "/?")
{
        print "usage: confirm_bet.pl \n";
        exit;
}
my $range=$ARGV[0];
my $secret=$ARGV[1];
my $tx=$ARGV[2];

my $seed = Digest::SHA::hmac_sha512_hex($tx, $secret); # hash txid and secret
$seed =~ s/^(.{8}).*$/$1/; # use 1st 8 characters of hash for secret
$seed = hex($seed) + 0; # convert hex to number
my $gen = Math::Random::MT->new($seed); # seed MT

my $number = int($gen->rand($range)+1); # generate random result inside game range using seeded MT

print "Result: $number\n";
exit;



Jump to: