This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: updated patch on the sysread, syswrite for VMS
[perl5.git] / t / op / rand.t
CommitLineData
a0d0e21e
LW
1#!./perl
2
748a9306 3# From: kgb@ast.cam.ac.uk (Karl Glazebrook)
a0d0e21e 4
748a9306 5print "1..4\n";
a0d0e21e 6
748a9306 7srand;
a0d0e21e 8
748a9306
LW
9$m=0;
10for(1..1000){
11 $n = rand(1);
12 if ($n<0 || $n>=1) {
13 print "not ok 1\n# The value of randbits is likely too low in config.sh\n";
14 exit
15 }
16 $m += $n;
17
18}
19$m=$m/1000;
20print "ok 1\n";
21
22if ($m<0.4) {
23 print "not ok 2\n# The value of randbits is likely too high in config.sh\n";
24}
25elsif ($m>0.6) {
26 print "not ok 2\n# Something's really weird about rand()'s distribution.\n";
27}else{
28 print "ok 2\n";
a0d0e21e
LW
29}
30
748a9306 31srand;
a0d0e21e 32
748a9306
LW
33$m=0;
34for(1..1000){
35 $n = rand(100);
36 if ($n<0 || $n>=100) {
37 print "not ok 3\n";
38 exit
39 }
40 $m += $n;
41
42}
43$m=$m/1000;
44print "ok 3\n";
45
46if ($m<40 || $m>60) {
47 print "not ok 4\n";
48}else{
49 print "ok 4\n";
a0d0e21e
LW
50}
51
748a9306 52