mindspore.ops.UniformInt
- class mindspore.ops.UniformInt(seed=0, seed2=0)[source]
Produces random integer values i, uniformly distributed on the closed interval [minval, maxval), that is, distributed according to the discrete probability function:
\[\text{P}(i|a,b) = \frac{1}{b-a+1},\]where the \(a\) indicates the min distribution parameter, the \(b\) indicates the max distribution parameter.
Note
The number in tensor minval must be strictly less than maxval at any position after broadcasting.
If neither seed nor seed2 is assigned a non-zero value, a randomly generated seed is used instead.
- Parameters
- Inputs:
shape (Union[tuple, Tensor]) - The shape of random tensor to be generated. Only constant value is allowed.
minval (Tensor) - The distribution parameter, \(a\). It defines the minimum possibly generated value, with int32 data type. Only one number is supported.
maxval (Tensor) - The distribution parameter, \(b\). It defines the maximum possibly generated value, with int32 data type. Only one number is supported.
- Outputs:
Tensor. The shape is the same as the input ‘shape’, and the data type is int32.
- Raises
TypeError – If neither seed nor seed2 is an int.
TypeError – If shape is neither a tuple nor a Tensor.
TypeError – If neither minval nor maxval is a Tensor.
ValueError – If shape is not a constant value.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> shape = (2, 4) >>> minval = Tensor(1, mstype.int32) >>> maxval = Tensor(5, mstype.int32) >>> uniform_int = ops.UniformInt(seed=10) >>> output = uniform_int(shape, minval, maxval) >>> result = output.shape >>> print(result) (2, 4)