Jordan
Jordan

Reputation: 9911

Will System.Random.Next() always return the same sequence

I'm using System.Random and I was wondering. If I provide a specific seed, will the sequence of random numbers be the same on every computer on which the code is run? Will it continue to be the same with future releases (i.e. is it built into the spec?)

Upvotes: 3

Views: 205

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564531

If I provide a specific seed, will the sequence of random numbers be the same on every computer on which the code is run?

Yes. That is the point of a seed.

Will it continue to be the same with future releases (i.e. is it built into the spec?)

Most likely, but this isn't guaranteed. The documentation for System.Random states:

The current implementation of the Random class is based on Donald E. Knuth's subtractive random number generator algorithm. For more information, see D. E. Knuth. "The Art of Computer Programming, volume 2: Seminumerical Algorithms". Addison-Wesley, Reading, MA, second edition, 1981.

The wording there does leave it open for a future implementation to change algorithms.

Upvotes: 5

Related Questions