mindspore.ops.randperm
- mindspore.ops.randperm(n, seed=0, offset=0, dtype=mstype.int64)[source]
Generates a random permutation of integers from 0 to n-1.
Warning
The Ascend backend does not support the reproducibility of random numbers, so the seed parameter has no effect.
Non-backward-compatible change after version 2.9.0: seed and offset will be removed, and the interface will use generator instead.
- Parameters
seed (int, optional) – Random seed. Default
0. When seed is -1, offset is 0, it's determined by time.offset (int, optional) – Offset to generate random numbers. Priority is higher than random seed. Default
0. It must be non-negative.dtype (mindspore.dtype, optional) – The data type returned. Default
mstype.int64.
- Returns
Tensor. Its shape is specified by the required args n.
- Supported Platforms:
CPU
Examples
>>> import mindspore >>> n, seed, offset = 4, 0, 0 >>> output = mindspore.ops.randperm(n, seed, offset, dtype=mindspore.int64) >>> print(output) [0 2 1 3]