Random seed of zero yields nondeterministic results

For a given seed, any Random object initialized with that seed should always produce the same sequence of numbers. This works for most seeds, but Random objects initialized with a seed of 0 appear to give a different sequence of numbers every time they’re created.

image
^ command line output

This is consistently reproducible for me. I’m on Windows 8.

1 Like

Random.new

Random.new(double seed)

Description:
Creates a new Random object from the given seed. If a seed isn’t specified, one will automatically be pulled from an internal entropy source.

I wonder if it is considering 0 as nil and is pulling a seed from your machine, which is consistent?

1 Like

That would be my guess. I think almost everyone would by default assume zero is as valid a seed as any, and is distinct from passing nil. So this behavior is a bit surprising (and I’m guessing not intentional). It just took me an hour to hunt down a bug in my game because I made this assumption.

2 Likes

Our RNG should be deterministic for all seed values; we don’t special-case zero afaik. Will look into it.

6 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.