I have a function that uses randomized numbers to generate its output. I would like to seed these random numbers with a long string; as long as the string is the same, the sequence of random numbers will be the same. This is mainly for testing purposes, but also for repeatability.
I plan to create a wrapper class that acts as a built-in System.Random class with the following constructor property:
MyRandom mr = new MyRandom(100, "This is a really long string...");
This generates an internal list of numbers, so when mr.Next () is called, it simply returns the next entry in the list. When it reaches 100, the list just wraps around. I would like to be able to call .NextDouble () too. This does not mean that you have high performance, I just want to create a random list and use it again.
How to convert a long string to a list of random numbers. I was thinking about taking the string length and diving by the number n (in this case, 100). Then splitting the string and calling a hash on each segment.
Is this a reasonable way to do this, or is there another, better method?
Shawn source
share