mindspore.Generator

View Source On AtomGit
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, random functions generate the same random sequence.

Note

Graph mode does not support the use of multiple generators at the same time for now.

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, the generator state.

initial_seed()[source]

Return the initial seed of the generator.

Returns:

int, the initial seed of the generator.

manual_seed(seed)[source]

Set the generator seed.

Parameters:

seed (int) – The seed value for the generator.

Returns:

Generator, the generator instance.

seed()[source]

Seed the generator with a random number.

Returns:

int, the randomly generated seed.

set_state(state)[source]

Set the generator state.

Parameters:

state (Tensor) – Target state of the generator.