7

I need to send an identical sequence of random numbers to a distributed network of applications.

Since such sequence might be quite long, I was thinking about sending just a (randomly generated) centralized seed initialization number and the length of the desired sequence.

Given that every component on the receiving hand will use the same .NET version, would that be a viable solution to have identical random data generated on all of my nodes?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Andrea
  • 884
  • 1
  • 10
  • 23
  • 1
    See http://stackoverflow.com/questions/17094189/crossplatform-random-number-generator – drch Jun 26 '13 at 12:00
  • Thanks for the pointer. Would you care to write this as an answer so that I can mark as accepted? – Andrea Jun 26 '13 at 12:03

2 Answers2

10

You should be able to distribute a seed for Random(int seed) and recreate the same sequence assuming that you are using the same version of .NET in all environments.

Remarks on System.Random @ MSDN

Notes to Callers The implementation of the random number generator in the Random class is not guaranteed to remain the same across major versions of the .NET Framework. As a result, your application code should not assume that the same seed will result in the same pseudo-random sequence in different versions of the .NET Framework.

If you can see a case where the framework version will change, or if you may need to recreate an old sequence after you've started using a new version, you'll want to create your own random implementation.

See the answers of this question for pointers: Crossplatform random number generator

Community
  • 1
  • 1
drch
  • 3,040
  • 1
  • 18
  • 29
1

You can use the Random class with a seed or use a service oriented architecture.

Random when initialized with a seed will produce an identical sequence.

Dustin Kingen
  • 20,677
  • 7
  • 52
  • 92
  • 3
    There's a major caveat to this which has been discussed on SO before. See drch's answer. – jerry Jun 26 '13 at 12:18