Given a consistently seeded Random:
Random r = new Random(0);
Calling r.Next()
consistently produces the same series; so is there a way to quickly discover the N-th value in that series, without calling r.Next()
N times?
My scenario is a huge array of values created via r.Next()
. The app occasionally reads a value from the array at arbitrary indexes. I'd like to optimize memory usage by eliminating the array and instead, generating the values on demand. But brute-forcing r.Next()
5 million times to simulate the 5 millionth index of the array is more expensive than storing the array. Is it possible to short-cut your way to the Nth .Next() value, without / with less looping?