-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandtest
executable file
·49 lines (44 loc) · 1.05 KB
/
randtest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env perl
# Copyright (c) 2008 Vsevolod Kozlov <[email protected]>
# License: Public Domain.
#
# Tool for testing your beloved RNG.
# Usage:
# randtest [-l <limit>] [-r <rounds>] [-R <rand() per round>]
#
use strict;
use warnings;
use vars qw|$VERSION|;
$VERSION='1.1';
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
my %options;
getopts('qR:r:l:', \%options);
my $limit = $options{l} || rand;
my $rounds = $options{r} || 1;
my $one_round = $options{R} || 100;
my $quiet = $options{q};
my $hits = 0;
my ($randval, $total, $i);
$| = 1; # Autoflush.
print ".", "-" x $one_round, ".\n" unless ($quiet);
for ($i = 0; $i < $rounds; ++$i)
{
print "|" unless ($quiet);
foreach (1..$one_round)
{
$randval = rand();
if ($randval <= $limit)
{
print "." unless ($quiet);
$hits++;
} else {
print " " unless ($quiet);
}
$total++;
}
print "|\n" unless ($quiet);
}
print "'", "-" x $one_round, "'\n\n" unless($quiet);
print "$total rand() calls ($one_round*$rounds)\n";
print $hits*100/$total . "% less or equal to $limit\n";