For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
randn
def randn[dtype: DType](span: Span[Scalar[dtype]], mean: Float64 = 0, standard_deviation: Float64 = 1)
Fills memory with random values from a Normal distribution.
Constraints:
The type should be floating point.
Parameters:
- dtype (
DType): The dtype of the pointer.
Args:
- span (
Span[Scalar[dtype]]): The memory area to fill. - mean (
Float64): The mean of the normal distribution. - standard_deviation (
Float64): The standard deviation of the normal distribution.
def randn[dtype: DType](ptr: UnsafePointer[Scalar[dtype], 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
seed()
var size: Int = 10
var data = List(length=size, fill=Float64(0))
randn(data, mean=0.0, standard_deviation=1.0)
for i in range(size):
print(data[i]) # Random Float64 from Normal(0.0, 1.0)
Constraints:
The type should be floating point.
Parameters:
- dtype (
DType): The dtype of the pointer.
Args:
- ptr (
UnsafePointer[Scalar[dtype], address_space=ptr.address_space]): 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.