randint¶
- paddle. randint ( low=0, high=None, shape=[1], dtype=None, name=None ) [source]
- 
         Returns a Tensor filled with random integers from a discrete uniform distribution in the range [ low,high), withshapeanddtype. Ifhighis None (the default), the range is [0,low).- Parameters
- 
           - 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 (list|tuple|Tensor, optional) – The shape of the output Tensor. If - shapeis a list or tuple, the elements of it should be integers or Tensors (with the shape [1], and the data type int32 or int64). If- shapeis a Tensor, it should be a 1-D Tensor(with the data type int32 or int64). Default is [1].
- 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. 
 
- Returns
- 
           A Tensor filled with random integers from a discrete uniform distribution in the range [ low,high), withshapeanddtype.
- 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=[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(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=[3], dtype='int32') # [-5, 4, -4] # random # example 5: # Input only one parameter # low=0, high=10, shape=[1], dtype='int64' out5 = paddle.randint(10) # [7] # random 
