randint(low: int, high: int, size: list[int] | tuple[int, ...], dtype: DTypeLike = None, device: DeviceLike = None, requires_grad: bool = False, generator: _C_engine.Generator | None = None)Implementing kernel
C++ engine symbols that back this Python API.Return a tensor of samples drawn from the discrete uniform distribution.
Each element is drawn independently and uniformly from the integer set , i.e. the discrete uniform distribution:
The distribution has mean and variance .
Parameters
lowintLower bound of the interval (inclusive). Leave it out for the
reference's two-argument spelling
randint(high, size), which
draws from [0, high).highintUpper bound of the interval (exclusive). Must satisfy
high > low.sizelist[int] or tuple[int, ...]Shape of the output tensor. Unlike
rand / randn, size
is a single required keyword-positional argument, not varargs.dtypelucid.dtype= NoneInteger data type. Defaults to
lucid.int64.devicestr or lucid.device= NoneTarget device —
"cpu" or "metal".requires_ gradbool= FalseEnable autograd tracking. Default:
False. Gradients through
integer tensors are always zero; this flag is accepted for
compatibility with downstream wrappers.Explicit generator. Defaults to the global default generator.
Returns
TensorInteger tensor of shape size with values in .
Raises
lucid._C.engine.InvalidArgumenthigh <= low, or dtype cannot hold low or high - 1
(int8 past 127): such a draw used to wrap round.Notes
The engine generates the integers via for , giving an exact discrete uniform distribution with no acceptance–rejection overhead. Common uses include sampling mini-batch indices, generating random class labels, and stochastic depth masks.
Examples
>>> import lucid
>>> _ = lucid.manual_seed(0)
>>> x = lucid.randint(0, 10, (5,))
>>> x.shape, x.dtype
((5,), lucid.int64)
>>> bool(((x >= 0) & (x < 10)).all())
True
>>> lucid.randint(10, (5,)).shape # high only: values in [0, 10)
(5,)
>>> idx = lucid.randint(0, 1024, (64,)) # sample 64 indices
>>> mask = lucid.randint(0, 2, (3, 4)) # values in {0, 1}