warp.randf#
- warp.randf(state: uint32) float#
Kernel
Python
Generate a uniform random float in the range [0.0, 1.0).
In a kernel, advances
statein place, so successive calls return different values; called from the Python scope, it does not modifystate, so repeated calls with the samestatereturn the same value (seerand_init()). Values are multiples of 2^-24, matching the 24 bits of precision in a 32-bit float.Random built-ins take an RNG
stateproduced byrand_init(); initialize it once per thread, then draw values:@wp.kernel def random_floats(seed: int, out: wp.array[wp.vec2]): i = wp.tid() rng = wp.rand_init(seed, i) # Each call advances rng, so the two draws differ. out[i] = wp.vec2(wp.randf(rng), wp.randf(rng))
randi(),randu(), andrandn()are used the same way: initializerngonce withrand_init(), then pass it to each call.
- warp.randf( ) float
Kernel
Python
Generate a uniform random float in the range [low, high).
In a kernel, advances
statein place, so successive calls return different values; called from the Python scope, it does not modifystate, so repeated calls with the samestatereturn the same value (seerand_init()). Equivalent tolow + (high - low) * wp.randf(state).