- paddle. randint ( low=0, high=None, shape=, dtype=None, name=None )
Returns a Tensor filled with random integers from a discrete uniform distribution in the range [
highis None (the default), the range is [0,
low (int, optional) – The lower bound on the range of random values to generate. The
lowis included in the range. If
highis None, the range is [0,
low). Default is 0.
high (int, optional) – The upper bound on the range of random values to generate, the
highis excluded in the range. Default is None (see above for behavior if high = None). Default is None.
shape (tuple|list|Tensor) – Shape of the Tensor to be created. The data type is
shapeis a list or tuple, each element of it should be integer or 0-D Tensor with shape . If
shapeis an Tensor, it should be an 1-D Tensor which represents a list. Default is .
dtype (str|np.dtype, optional) – The data type of the output tensor. Supported data types: int32, int64. If
dytpeis 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.
A Tensor filled with random integers from a discrete uniform distribution in the range [
- Return type
import paddle # example 1: # attr shape is a list which doesn't contain Tensor. out1 = paddle.randint(low=-5, high=5, shape=[2, 3]) # [0, -3, 2] # random # example 2: # attr shape is a list which contains Tensor. dim1 = paddle.to_tensor(2, 'int64') dim2 = paddle.to_tensor(3, '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([2, 3]) out3 = paddle.randint(low=-5, high=5, shape=shape_tensor) # [[ 2, -3, -1], # random # [-3, -2, 1]]) # 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