--- a/Random.st Wed Aug 11 19:48:26 1999 +0200
+++ b/Random.st Thu Aug 12 11:42:31 1999 +0200
@@ -186,6 +186,40 @@
!Random class methodsFor:'testing'!
+bucketTest: randy
+ "A quick-and-dirty bucket test. Prints nbuckets values on the Transcript.
+ Each should be 'near' the value of ntries. Any run with any value 'far' from ntries
+ indicates something is very wrong. Each run generates different values.
+ For a slightly better test, try values of nbuckets of 200-1000 or more;
+ go get coffee.
+ This is a poor test; see Knuth.
+ Some 'OK' runs:
+ 1000 1023 998 969 997 1018 1030 1019 1054 985 1003
+ 1011 987 982 980 982 974 968 1044 976
+ 1029 1011 1025 1016 997 1019 991 954 968 999 991
+ 978 1035 995 988 1038 1009 988 993 976
+ "
+
+ | nbuckets buckets ntrys slot |
+
+ nbuckets := 20.
+ buckets := Array new: nbuckets.
+ buckets atAllPut: 0.
+ ntrys := 1000.
+ ntrys*nbuckets timesRepeat: [
+ slot := (randy next * nbuckets) floor + 1.
+ buckets at: slot put: (buckets at: slot) + 1 ].
+ Transcript cr.
+ 1 to: nbuckets do: [ :nb |
+ Transcript show: (buckets at: nb) printString, ' ' ]
+
+
+ "Execute this:
+ Random bucketTest: Random new
+ "
+
+!
+
chiSquareTest
" Chi-Squared Test - from R.Sedgewick's 1st ed. of 'Algorithms',
o N = number of samples
@@ -296,7 +330,6 @@
in the range 0 .. 16r3FFFFFFF.
From Sedgewick's 'Algorithms', based on Lehmer's method"
- "the times: is a kludge - times does not convert to LargeInteger on overflow"
self step.
^ seed
@@ -412,5 +445,5 @@
!Random class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/Random.st,v 1.21 1998-08-21 12:47:38 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Random.st,v 1.22 1999-08-12 09:42:31 cg Exp $'
! !