Randomly returns true ~"1/n" of the time, and false otherwise. REQUIRES: n > 0
| 51 | // Randomly returns true ~"1/n" of the time, and false otherwise. |
| 52 | // REQUIRES: n > 0 |
| 53 | bool OneIn(int n) { return (Next() % n) == 0; } |
| 54 | |
| 55 | // Skewed: pick "base" uniformly from range [0,max_log] and then |
| 56 | // return "base" random bits. The effect is to pick a number in the |
no outgoing calls