MCPcopy Index your code
hub / github.com/tinygrad/tinygrad / randint

Method randint

tinygrad/tensor.py:669–685  ·  view source on GitHub ↗

Creates a tensor with the given shape, filled with random integer values generated uniformly from the interval `[low, high)`. Requires `low < high`. If `dtype` is not specified, the default type is used. You can pass in the `device` keyword argument to control device of the tensor.

(*shape, low=0, high=10, dtype=dtypes.int32, **kwargs)

Source from the content-addressed store, hash-verified

667
668 @staticmethod
669 def randint(*shape, low=0, high=10, dtype=dtypes.int32, **kwargs) -> Tensor:
670 """
671 Creates a tensor with the given shape, filled with random integer values generated uniformly from the interval `[low, high)`.
672 Requires `low < high`. If `dtype` is not specified, the default type is used.
673
674 You can pass in the `device` keyword argument to control device of the tensor.
675 Additionally, all other keyword arguments are passed to the constructor of the tensor.
676
677 ```python exec="true" source="above" session="tensor" result="python"
678 Tensor.manual_seed(42)
679 print(Tensor.randint(2, 3, low=5, high=10).numpy())
680 ```
681 """
682 if not all_int([low, high]): raise TypeError(f"{low=} and {high=} must be integers")
683 if not dtypes.is_int(dtype := to_dtype(dtype)): raise TypeError(f"{dtype=} must be int")
684 if low >= high: raise ValueError(f"Tensor.randint requires low < high, got {low=}, {high=}")
685 return Tensor.uniform(*shape, low=low, high=high, dtype=dtype, **kwargs)
686
687 @staticmethod
688 def normal(*shape, mean=0.0, std=1.0, **kwargs) -> Tensor:

Callers 15

_get_valueFunction · 0.80
trainFunction · 0.80
prepareMethod · 0.80
fuzzer.pyFile · 0.80
prepareMethod · 0.80
prepareMethod · 0.80
prepareMethod · 0.80
prepareMethod · 0.80
fnMethod · 0.80
test_mnist_indexMethod · 0.80
backend.pyFile · 0.80
wr_speed.pyFile · 0.80

Calls 4

all_intFunction · 0.90
to_dtypeFunction · 0.90
is_intMethod · 0.80
uniformMethod · 0.80

Tested by 15

fnMethod · 0.64
test_mnist_indexMethod · 0.64
new_rand_listMethod · 0.64
test_tqdm_output_iterMethod · 0.64
test_unit_scaleMethod · 0.64
test_set_descriptionMethod · 0.64
test_tqdm_writeMethod · 0.64