Skip to content

Commit

Permalink
Add simple test of random number distribution.
Browse files Browse the repository at this point in the history
Rakudo JVM currently has a bug where rand_I is biased towards numbers at the
beginning of a range. This simple check should detect that by rolling a number
from 0 to 4, then summing up the number of times 3 or 4 was found. In a proper
random number generator, this should be on the order of 400. We check to see
if it is less than 300 and complain if it is.

This might happened by change to a good random number generator occasionally,
of course.
  • Loading branch information
colomon committed Jun 29, 2013
1 parent f4472d9 commit de39835
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion S32-num/rand.t
Expand Up @@ -4,7 +4,7 @@ use Test;
BEGIN { @*INC.push('t/spec/packages') };
use Test::Util;

plan 114;
plan 115;

=begin pod
Expand Down Expand Up @@ -104,6 +104,14 @@ lives_ok { srand(1) }, 'srand(1) lives and parses';
ok( $badness < 0.15, 'rand is pretty random' );
}

{
# this catches if the random number generator is biased toward
# smaller numbers in a range.
my %h;
%h{$_}++ for (^5).roll(1000);
ok %h<3> + %h<4> > 300, "Distribution is not very uneven";
}

# RT #113968
#?niecza skip "throws_like"
#?DOES 4
Expand Down

0 comments on commit de39835

Please sign in to comment.