fn
randint
→Tensorrandint(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)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).
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.dtypeInteger data type. Defaults to
lucid.int64.devicestr or lucid.deviceTarget device —
"cpu" or "metal".requires_gradboolEnable autograd tracking. Default:
False. Gradients through
integer tensors are always zero; this flag is accepted for
compatibility with downstream wrappers.generatorlucid._C.engine.GeneratorExplicit generator. Defaults to the global default generator.
Returns
TensorInteger tensor of shape size with values in .
Notes
The engine generates the integers via
which gives an exact discrete uniform distribution with no acceptance–rejection overhead.
Common uses include:
- Sampling mini-batch indices for data loaders
- Generating random class labels for testing
- Stochastic depth / drop-path masks
Examples
>>> import lucid
>>> lucid.manual_seed(0)
>>> lucid.randint(0, 10, (5,)).tolist()
[3, 6, 7, 9, 6]
Shuffle indices for a dataset of 1024 examples:
>>> idx = lucid.randint(0, 1024, (64,)) # sample 64 indices
Random binary mask:
>>> mask = lucid.randint(0, 2, (3, 4)) # values in {0, 1}