summaryrefslogtreecommitdiff
path: root/t/op/rand.t
diff options
context:
space:
mode:
Diffstat (limited to 't/op/rand.t')
-rwxr-xr-xt/op/rand.t57
1 files changed, 42 insertions, 15 deletions
diff --git a/t/op/rand.t b/t/op/rand.t
index 14e6ccfbed..5c0eccf15f 100755
--- a/t/op/rand.t
+++ b/t/op/rand.t
@@ -1,25 +1,52 @@
#!./perl
-#From jhi@snakemail.hut.fi Mon May 16 10:36:46 1994
-#Date: Sun, 15 May 1994 20:39:09 +0300
-#From: Jarkko Hietaniemi <jhi@snakemail.hut.fi>
+# From: kgb@ast.cam.ac.uk (Karl Glazebrook)
-print "1..2\n";
+print "1..4\n";
-$n = 1000;
+srand;
-$c = 0;
-for (1..$n) {
- last if (rand() > 1 || rand() < 0);
- $c++;
+$m=0;
+for(1..1000){
+ $n = rand(1);
+ if ($n<0 || $n>=1) {
+ print "not ok 1\n# The value of randbits is likely too low in config.sh\n";
+ exit
+ }
+ $m += $n;
+
+}
+$m=$m/1000;
+print "ok 1\n";
+
+if ($m<0.4) {
+ print "not ok 2\n# The value of randbits is likely too high in config.sh\n";
+}
+elsif ($m>0.6) {
+ print "not ok 2\n# Something's really weird about rand()'s distribution.\n";
+}else{
+ print "ok 2\n";
}
-if ($c == $n) {print "ok 1\n";} else {print "not ok 1\n"}
+srand;
-$c = 0;
-for (1..$n) {
- last if (rand(10) > 10 || rand(10) < 0);
- $c++;
+$m=0;
+for(1..1000){
+ $n = rand(100);
+ if ($n<0 || $n>=100) {
+ print "not ok 3\n";
+ exit
+ }
+ $m += $n;
+
+}
+$m=$m/1000;
+print "ok 3\n";
+
+if ($m<40 || $m>60) {
+ print "not ok 4\n";
+}else{
+ print "ok 4\n";
}
-if ($c == $n) {print "ok 2\n";} else {print "not ok 2\n"}
+