random
Module
Provides functions for random numbers.
You can import these APIs from the random
package. For example:
from random import seed
seed
seed()
Seeds the random number generator using the current time.
seed(a: Int)
Seeds the random number generator using the value provided.
Args:
- a (
Int
): The seed value.
random_float64
random_float64(min: SIMD[f64, 1], max: SIMD[f64, 1]) -> SIMD[f64, 1]
Returns a random Float64
number from the given range.
Args:
- min (
SIMD[f64, 1]
): The minimum number in the range (default is 0.0). - max (
SIMD[f64, 1]
): The maximum number in the range (default is 1.0).
Returns:
A random number from the specified range.
random_si64
random_si64(min: SIMD[si64, 1], max: SIMD[si64, 1]) -> SIMD[si64, 1]
Returns a random Int64
number from the given range.
Args:
- min (
SIMD[si64, 1]
): The minimum number in the range. - max (
SIMD[si64, 1]
): The maximum number in the range.
Returns:
A random number from the specified range.
random_ui64
random_ui64(min: SIMD[ui64, 1], max: SIMD[ui64, 1]) -> SIMD[ui64, 1]
Returns a random UInt64
number from the given range.
Args:
- min (
SIMD[ui64, 1]
): The minimum number in the range. - max (
SIMD[ui64, 1]
): The maximum number in the range.
Returns:
A random number from the specified range.
randint
randint[type: DType](ptr: DTypePointer[type], size: Int, low: Int, high: Int)
Fills memory with random values.
Constraints:
The type should be integral.
Parameters:
- type (
DType
): The dtype of the pointer.
Args:
- ptr (
DTypePointer[type]
): The pointer to the memory area to fill. - size (
Int
): The number of elements to fill. - low (
Int
): The minimal value for random. - high (
Int
): The maximal value for random.
rand
rand[type: DType](ptr: DTypePointer[type], size: Int)
Fills memory with random values from a uniform distribution.
Parameters:
- type (
DType
): The dtype of the pointer.
Args:
- ptr (
DTypePointer[type]
): The pointer to the memory area to fill. - size (
Int
): The number of elements to fill.
rand[type: DType](*shape: Int) -> Tensor[type]
Constructs a new tensor with the specified shape and fills it with random elements.
Parameters:
- type (
DType
): The dtype of the tensor.
Args:
- shape (
*Int
): The tensor shape.
Returns:
A new tensor of specified shape and filled with random elements.
rand[type: DType](owned shape: TensorShape) -> Tensor[type]
Constructs a new tensor with the specified shape and fills it with random elements.
Parameters:
- type (
DType
): The dtype of the tensor.
Args:
- shape (
TensorShape
): The tensor shape.
Returns:
A new tensor of specified shape and filled with random elements.
rand[type: DType](owned spec: TensorSpec) -> Tensor[type]
Constructs a new tensor with the specified specification and fills it with random elements.
Parameters:
- type (
DType
): The dtype of the tensor.
Args:
- spec (
TensorSpec
): The tensor specification.
Returns:
A new tensor of specified specification and filled with random elements.