183 "Created: 21.8.1997 / 18:07:00 / cg" |
183 "Created: 21.8.1997 / 18:07:00 / cg" |
184 "Modified: 21.8.1997 / 18:08:56 / cg" |
184 "Modified: 21.8.1997 / 18:08:56 / cg" |
185 ! ! |
185 ! ! |
186 |
186 |
187 !Random class methodsFor:'testing'! |
187 !Random class methodsFor:'testing'! |
|
188 |
|
189 bucketTest: randy |
|
190 "A quick-and-dirty bucket test. Prints nbuckets values on the Transcript. |
|
191 Each should be 'near' the value of ntries. Any run with any value 'far' from ntries |
|
192 indicates something is very wrong. Each run generates different values. |
|
193 For a slightly better test, try values of nbuckets of 200-1000 or more; |
|
194 go get coffee. |
|
195 This is a poor test; see Knuth. |
|
196 Some 'OK' runs: |
|
197 1000 1023 998 969 997 1018 1030 1019 1054 985 1003 |
|
198 1011 987 982 980 982 974 968 1044 976 |
|
199 1029 1011 1025 1016 997 1019 991 954 968 999 991 |
|
200 978 1035 995 988 1038 1009 988 993 976 |
|
201 " |
|
202 |
|
203 | nbuckets buckets ntrys slot | |
|
204 |
|
205 nbuckets := 20. |
|
206 buckets := Array new: nbuckets. |
|
207 buckets atAllPut: 0. |
|
208 ntrys := 1000. |
|
209 ntrys*nbuckets timesRepeat: [ |
|
210 slot := (randy next * nbuckets) floor + 1. |
|
211 buckets at: slot put: (buckets at: slot) + 1 ]. |
|
212 Transcript cr. |
|
213 1 to: nbuckets do: [ :nb | |
|
214 Transcript show: (buckets at: nb) printString, ' ' ] |
|
215 |
|
216 |
|
217 "Execute this: |
|
218 Random bucketTest: Random new |
|
219 " |
|
220 |
|
221 ! |
188 |
222 |
189 chiSquareTest |
223 chiSquareTest |
190 " Chi-Squared Test - from R.Sedgewick's 1st ed. of 'Algorithms', |
224 " Chi-Squared Test - from R.Sedgewick's 1st ed. of 'Algorithms', |
191 o N = number of samples |
225 o N = number of samples |
192 o r = range of random numners is [0,r) -- condition: N >= 10r. |
226 o r = range of random numners is [0,r) -- condition: N >= 10r. |