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)
| 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: |