Curious2learn
Curious2learn

Reputation: 33638

Can one use negative numbers as seeds for random number generation?

This is not a coding question, but am hoping that someone has come across this in the forums here. I am using Python to run some simulations. I need to run many replications using different random number seeds. I have two questions:

  1. Are negative numbers okay as seeds?
  2. Should I keep some distance in the seeds?

Currently I am using random.org to create 50 numbers between -100000 and +100000, which I use as seeds. Is this okay?

Thanks.

Upvotes: 2

Views: 4657

Answers (2)

Matt Joiner
Matt Joiner

Reputation: 118590

Quoting random.seed([x]):

Optional argument x can be any hashable object.

Both positive and negative numbers are hashable, and many other objects besides.

>>> hash(42)
42
>>> hash(-42)
-42
>>> hash("hello")
-1267296259
>>> hash(("hello", "world"))
759311865

Upvotes: 8

Philip Potter
Philip Potter

Reputation: 9135

Is it important that your simulations are repeatable? The canonical way to seed a RNG is by using the current system time, and indeed this is random's default behaviour:

random.seed([x])

Initialize the basic random number generator. Optional argument x can be any hashable object. If x is omitted or None, current system time is used; current system time is also used to initialize the generator when the module is first imported.

I would only deviate from this behaviour if repeatability is important. If it is important, then your random.org seeds are a reasonable solution.

Should I keep some distance in the seeds?

No. For a good quality RNG, the choice of seed will not affect the quality of the output. A set of seeds [1,2,3,4,5,6,7,8,9,10] should result in the same quality of randomness as any random selection of 10 ints. But even if a selection of random uniformly-distributed seeds were desirable, maintaining some distance would break that distribution.

Upvotes: 5

Related Questions