examples/math/int-dist.ck
raw| 1 | // name: int-dist.ck |
| 2 | // desc: testing int random distribution over range |
| 3 | |
| 4 | // how many buckets |
| 5 | 10 => int N; |
| 6 | |
| 7 | // buckets |
| 8 | int count[N]; |
| 9 | |
| 10 | // how many times |
| 11 | repeat( 100000 ) |
| 12 | { |
| 13 | // which bucket? |
| 14 | count[Math.random2(0,N-1)]++; |
| 15 | } |
| 16 | |
| 17 | // go over buckets |
| 18 | for( int i; i < N; i++ ) |
| 19 | { |
| 20 | // print bucket contents |
| 21 | cherr <= count[i] <= IO.nl(); |
| 22 | } |