mindspore.Generator

View Source On Gitee
class mindspore.Generator[source]

A generator that manages the state of random numbers and provides seed and offset for random functions. When the seed and offset are fixed, the random function generates the same random sequence.

Inputs:
  • step (int) - Set the step size for offset update.

Outputs:

Tuple consisting of the seed and offset of generator.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore as ms
>>> from mindspore import Generator
>>> generator = Generator()
>>> generator.manual_seed(5)
>>> print(generator.initial_seed())
5
>>> state = generator.get_state()
>>> generator.seed()
>>> generator.set_state(state)
>>> print(generator.initial_seed())
5
get_state()[source]

Get the generator state.

Returns

Tensor, generator state.

initial_seed()[source]

Return the initial seed of generator.

Returns

The initial seed of generator.

manual_seed(seed)[source]

Set the generator seed.

Parameters

seed (int) – Set the generator seed.

Returns

Generator, the generator instance.

seed()[source]

Seed generator with random number.

Returns

Randomly generated seeds, the type is int.

set_state(state)[source]

Sets the generator state.

Parameters

state (tensor) – target state of the generator.