Mojo function
randn
randn[dtype: DType](ptr: UnsafePointer[Scalar[dtype], ptr.origin, address_space=ptr.address_space], size: Int, mean: Float64 = 0, standard_deviation: Float64 = 1)
Fills memory with random values from a Normal distribution.
Example:
from std.random import randn, seed
from std.memory import alloc
seed()
var size: Int = 10
var ptr = alloc[Float64](size)
randn[DType.float64](ptr, size, mean=0.0, standard_deviation=1.0)
for i in range(size):
print(ptr[i]) # Random Float64 from Normal(0.0, 1.0)
ptr.free()Constraints:
The type should be floating point.
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. - mean (
Float64): The mean of the normal distribution. - standard_deviation (
Float64): The standard deviation of the normal distribution.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!