Skip to content

Unexpected behaviour of spawned numpy.random.SeedSequence #16539

@mreineck

Description

@mreineck

I'm running this test snippet using numpy 1.18.4 and am a bit confused about the output:

import numpy as np

print(np.version.full_version)

sseq = np.random.SeedSequence(42)
sseq_child = sseq.spawn(1)[0]

rng = np.random.default_rng(sseq)
rng_child = np.random.default_rng(sseq_child)

print(rng.random(10) - rng_child.random(10))

This outputs ten zeros, which surprises me. I would have expected that the first child sequence spawned from sseq would actually be different from sseq itself, but it appears to be in fact identical.

Is this intended? If so, I didn't see any mention of this in the documentation, and I'm a bit worried that people will actually expect (like I did) that random numbers generated from a SeedSequence object and its children would be totally independent.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions