|
105 | 105 | product = random.u64.wide_multiply(limit) |
106 | 106 | // Reject and try again if the tail happens to be in the zone of bias. |
107 | 107 | // The loop will continue generating new numbers until we get a good sample. |
108 | | - if (product.tail < limit) ( |
| 108 | + if product.tail < limit ( |
109 | 109 | threshold = limit.negate % limit |
110 | | - while (product.tail < threshold) ( |
| 110 | + while product.tail < threshold ( |
111 | 111 | product = random.u64.wide_multiply(limit) |
112 | 112 | ) |
113 | 113 | ) |
|
128 | 128 | product = random.u32.wide_multiply(limit) |
129 | 129 | // Reject and try again if the tail happens to be in the zone of bias. |
130 | 130 | // The loop will continue generating new numbers until we get a good sample. |
131 | | - if (product.tail < limit) ( |
| 131 | + if product.tail < limit ( |
132 | 132 | threshold = limit.negate % limit |
133 | | - while (product.tail < threshold) ( |
| 133 | + while product.tail < threshold ( |
134 | 134 | product = random.u32.wide_multiply(limit) |
135 | 135 | ) |
136 | 136 | ) |
|
146 | 146 | :: If you need fully unbiased results, use the `unbiased_u32_less_than` |
147 | 147 | :: method instead, which discards all samples from the biased zone. |
148 | 148 | :fun ref usize_less_than(limit USize) |
149 | | - if (USize.bit_width == 32) ( |
| 149 | + if USize.bit_width == 32 ( |
150 | 150 | @u32_less_than(limit.u32).usize |
151 | 151 | | |
152 | 152 | @u64_less_than(limit.u64).usize |
|
162 | 162 | :: To keep maximum performance at the cost of some possibility of bias, |
163 | 163 | :: use the `uSize_less_than` method instead, which never discards results. |
164 | 164 | :fun ref unbiased_usize_less_than(limit USize) USize |
165 | | - if (USize.bit_width == 32) ( |
| 165 | + if USize.bit_width == 32 ( |
166 | 166 | @unbiased_u32_less_than(limit.u32).usize |
167 | 167 | | |
168 | 168 | @unbiased_u64_less_than(limit.u64).usize |
|
186 | 186 | :fun ref random_bytes(size USize) Bytes |
187 | 187 | bytes = Bytes.new_iso(size) |
188 | 188 |
|
189 | | - while (size > 0) ( |
| 189 | + while size > 0 ( |
190 | 190 | case size > ( |
191 | 191 | | 8 | bytes.push_native_u64(@u64), size -= 8 |
192 | 192 | | 4 | bytes.push_native_u32(@u32), size -= 4 |
|
0 commit comments