(frequency[] a)
| 68 | |
| 69 | // naive |
| 70 | public static final byte selectRandom(frequency[] a) { |
| 71 | int len = a.length; |
| 72 | double r = random(1.0); |
| 73 | for (int i = 0; i < len; i++) |
| 74 | if (r < a[i].p) |
| 75 | return a[i].c; |
| 76 | return a[len - 1].c; |
| 77 | } |
| 78 | |
| 79 | static int BUFFER_SIZE = 1024; |
| 80 | static int index = 0; |