MCPcopy Create free account
hub / github.com/numpy/numpy / rk_random_uint64

Function rk_random_uint64

numpy/random/src/mt19937/randomkit.c:267–297  ·  view source on GitHub ↗

* Fills an array with cnt random npy_uint64 between off and off + rng * inclusive. The numbers wrap if rng is sufficiently large. */

Source from the content-addressed store, hash-verified

265 * inclusive. The numbers wrap if rng is sufficiently large.
266 */
267void rk_random_uint64(npy_uint64 off, npy_uint64 rng, npy_intp cnt,
268 npy_uint64 *out, rk_state *state) {
269 npy_uint64 val, mask = rng;
270 npy_intp i;
271
272 if (rng == 0) {
273 for (i = 0; i < cnt; i++) {
274 out[i] = off;
275 }
276 return;
277 }
278
279 /* Smallest bit mask >= max */
280 mask |= mask >> 1;
281 mask |= mask >> 2;
282 mask |= mask >> 4;
283 mask |= mask >> 8;
284 mask |= mask >> 16;
285 mask |= mask >> 32;
286
287 for (i = 0; i < cnt; i++) {
288 if (rng <= 0xffffffffUL) {
289 while ((val = (rk_uint32(state) & mask)) > rng)
290 ;
291 } else {
292 while ((val = (rk_uint64(state) & mask)) > rng)
293 ;
294 }
295 out[i] = off + val;
296 }
297}
298
299/*
300 * Fills an array with cnt random npy_uint32 between off and off + rng

Callers

nothing calls this directly

Calls 2

rk_uint32Function · 0.85
rk_uint64Function · 0.85

Tested by

no test coverage detected