Mojo function
randint
randint[dtype: DType](ptr: UnsafePointer[Scalar[dtype], ptr.origin], size: Int, low: Int, high: Int) where dtype.is_integral()
Fills memory with uniformly distributed random integers in the range [low, high].
Example:
from std.random import randint, seed
from std.memory import alloc
seed()
var size: Int = 10
var ptr = alloc[Int32](size)
randint[DType.int32](ptr, size, -50, 50)
for i in range(size):
print(ptr[i]) # Random Int32 between -50 and 50
ptr.free()Constraints:
The type must be integral.
Parameters:
- dtype (
DType): The dtype of the pointer.
Args:
- ptr (
UnsafePointer): The pointer to the memory area to fill. - size (
Int): The number of elements to fill. - low (
Int): The inclusive lower bound. - high (
Int): The inclusive upper bound.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!