# randint¶

`paddle.` `randint` ( low=0, high=None, shape=, dtype=None, name=None ) [source]

This OP returns a Tensor filled with random integers from a discrete uniform distribution in the range [`low`, `high`), with `shape` and `dtype`. If `high` is None (the default), the range is [0, `low`).

Parameters
• low (int) – The lower bound on the range of random values to generate. The `low` is included in the range. If `high` is None, the range is [0, `low`). Default is 0.

• high (int, optional) – The upper bound on the range of random values to generate, the `high` is excluded in the range. Default is None (see above for behavior if high = None). Default is None.

• shape (list|tuple|Tensor) – The shape of the output Tensor. If `shape` is a list or tuple, the elements of it should be integers or Tensors (with the shape , and the data type int32 or int64). If `shape` is a Tensor, it should be a 1-D Tensor(with the data type int32 or int64). Default is .

• dtype (str|np.dtype, optional) – The data type of the output tensor. Supported data types: int32, int64. If `dytpe` is None, the data type is int64. Default is None.

• name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.

Returns

A Tensor filled with random integers from a discrete uniform distribution in the range [`low`, `high`), with `shape` and `dtype`.

Return type

Tensor

Examples

```import paddle

# example 1:
# attr shape is a list which doesn't contain Tensor.
out1 = paddle.randint(low=-5, high=5, shape=)
# [0, -3, 2]  # random

# example 2:
# attr shape is a list which contains Tensor.
dim1 = paddle.to_tensor(, 'int64')
dim2 = paddle.to_tensor(, 'int32')
out2 = paddle.randint(low=-5, high=5, shape=[dim1, dim2])
# [[0, -1, -3],  # random
#  [4, -2,  0]]  # random

# example 3:
# attr shape is a Tensor
shape_tensor = paddle.to_tensor(3)
out3 = paddle.randint(low=-5, high=5, shape=shape_tensor)
# [-2, 2, 3]  # random

# example 4:
# data type is int32
out4 = paddle.randint(low=-5, high=5, shape=, dtype='int32')
# [-5, 4, -4]  # random

# example 5:
# Input only one parameter
# low=0, high=10, shape=, dtype='int64'
out5 = paddle.randint(10)
#   # random
```