[inseparable changes from patch from perl5.003_15 to perl5.003_16]
[p5sagit/p5-mst-13.2.git] / t / op / rand.t
1 #!./perl
2
3 # From: kgb@ast.cam.ac.uk (Karl Glazebrook)
4
5 print "1..4\n";
6
7 srand;
8
9 $m=0; 
10 for(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;
20 print "ok 1\n";
21
22 if ($m<0.4) {
23     print "not ok 2\n# The value of randbits is likely too high in config.sh\n";
24 }
25 elsif ($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";
29 }
30
31 srand;
32
33 $m=0; 
34 for(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;
44 print "ok 3\n";
45
46 if ($m<40 || $m>60) {
47     print "not ok 4\n";
48 }else{
49     print "ok 4\n";
50 }
51
52