File::Copy under OS/2
[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..6\n";
6
7 srand;
8
9 $m=$max=0; 
10 for(1..1000){ 
11    $n = rand(1);
12    if ($n<0) {
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    $max = $n if $n > $max;
18 }
19 $m=$m/1000;
20 print "ok 1\n";
21
22 $off = log($max)/log(2);
23 if ($off > 0) { $off = int(.5+$off) }
24     else { $off = - int(.5-$off) }
25 print "# Consider adding $off to randbits\n" if $off > 0;
26 print "# Consider subtracting ", -$off, " from randbits\n" if $off < 0;
27
28 if ($m<0.4) {
29     print "not ok 2\n# The value of randbits is likely too high in config.sh\n";
30 }
31 elsif ($m>0.6) {
32     print "not ok 2\n# The value of randbits is likely too low in config.sh\n";
33 }else{
34     print "ok 2\n";
35 }
36
37 srand;
38
39 $m=0; 
40 for(1..1000){ 
41    $n = rand(100);
42    if ($n<0 || $n>=100) {
43        print "not ok 3\n";
44        exit
45    }
46    $m += $n;
47
48 }
49 $m=$m/1000;
50 print "ok 3\n";
51
52 if ($m<40 || $m>60) {
53     print "not ok 4\n";
54 }else{
55     print "ok 4\n";
56 }
57
58 srand(3.14159);
59 $r = rand;
60 srand(3.14159);
61 print "# srand is not consistent.\nnot " if rand != $r;
62 print "ok 5\n";
63
64 print "# rand is unchanging!\nnot " if rand == $r;
65 print "ok 6\n";
66