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.

  • Random seed: a set of regular random numbers can be obtained through some complex mathematical algorithms, and the random seed is the initial value of this random number. If the random seed is the same in two separate calls, the random number generated will not change.

  • Global random seed and operator-level random seed are not set or both set to 0: behavior is completely random.

  • Global random seed is set, but operator-level random seed is not set: A global random seed will splice with 0 to generate random number.

  • Global random seed is not set, operator-level random seed is set: 0 splices with the operator-level random seed to generate random number.

  • Both Global random and operator-level random seed are set: the global random seed will splice with the operator-level random seed to generate random number.

Parameters
  • seed (int, optional) – The operator-level random seed, used to generate random numbers, must be non-negative. Default: 0 .

  • seed2 (int, optional) – The global random seed, which combines with the operator-level random seed to determine the final generated random number, must be non-negative. Default: 0 .

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

>>> from mindspore import Tensor, ops
>>> from mindspore import dtype as mstype
>>> 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)