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

Function rk_random_uint32

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

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

Source from the content-addressed store, hash-verified

301 * inclusive. The numbers wrap if rng is sufficiently large.
302 */
303void rk_random_uint32(npy_uint32 off, npy_uint32 rng, npy_intp cnt,
304 npy_uint32 *out, rk_state *state) {
305 npy_uint32 val, mask = rng;
306 npy_intp i;
307
308 if (rng == 0) {
309 for (i = 0; i < cnt; i++) {
310 out[i] = off;
311 }
312 return;
313 }
314
315 /* Smallest bit mask >= max */
316 mask |= mask >> 1;
317 mask |= mask >> 2;
318 mask |= mask >> 4;
319 mask |= mask >> 8;
320 mask |= mask >> 16;
321
322 for (i = 0; i < cnt; i++) {
323 while ((val = (rk_uint32(state) & mask)) > rng)
324 ;
325 out[i] = off + val;
326 }
327}
328
329/*
330 * Fills an array with cnt random npy_uint16 between off and off + rng

Callers

nothing calls this directly

Calls 1

rk_uint32Function · 0.85

Tested by

no test coverage detected