IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Mojo function

random_uniform

def random_uniform[dtype: DType, rank: Int, //, target: StringSlice[ImmStaticOrigin], OutputFn: def[width: SIMDLength, _rank: Int](idx: IndexList[_rank], val: SIMD[dtype, width]) -> None & ImplicitlyCopyable & RegisterPassable](shape: IndexList[rank], lower_bound: Scalar[dtype], upper_bound: Scalar[dtype], seed_ptr: Pointer[UInt64, ImmutAnyOrigin, _safe=False], ctx: DeviceContext, output_fn: OutputFn) where (eq OutputFn.dtype, dtype)

Call output_fn with values generated from a uniform distribution on [lower_bound, upper_bound] for floating-point types or [lower_bound, upper_bound) for integer types.

Parameters:

  • ​dtype (DType): The data type to generate.
  • ​rank (Int): The rank of the underlying buffer.
  • ​target (StringSlice[ImmStaticOrigin]): The target to run on.
  • ​OutputFn (def[width: SIMDLength, _rank: Int](idx: IndexList[_rank], val: SIMD[dtype, width]) -> None & ImplicitlyCopyable & RegisterPassable): The type of the function which stores the generated values.

Args:

  • ​shape (IndexList[rank]): The shape of the output being stored into by output_fn.
  • ​lower_bound (Scalar[dtype]): The lower bound on the uniform range.
  • ​upper_bound (Scalar[dtype]): The upper bound on the uniform range.
  • ​seed_ptr (Pointer[UInt64, ImmutAnyOrigin, _safe=False]): Pointer to a single uint64 in device memory containing the Philox seed.
  • ​ctx (DeviceContext): The device context.
  • ​output_fn (OutputFn): The function which stores the generated values.

Was this page helpful?