Hello!
I had an idea about random generation based on seeded rand(), but there is one caveat to make it work correctly (I think). I need to be able to predict rand() at any positive offset based on its seed, without actually having to call it every single time inbetween.
Let us assume that this code:
1 2 3 4 5 6 7 8
|
unsigned int max_iters = 5;
srand(SEEDVALUE);
for(int i = 0; i < max_iters; ++i)
{
cout << rand() % 100 << endl;
}
|
assume that this code outputs the values: 59, 3, 12, 34, 95
And it would always output the same exact numbers, provided that SEEDVALUE is the same value every time you run it. This means if I change "max_iters" to 100, the very last generated number (100th, or value #99) will always be the same value, too.
This means, if I wanted to store ONLY what the first ten values, and the last ten values were (when using a certain SEEDVALUE), I could "always know" those results, provided that I actually run rand() the full 100 times. I just don't care about those 80 results in the middle, but that's fine, I'll just run rand() the first 10 times, store the first 10 values, run it 80 more times, throw away those 80 values, and run it 10 more times, and store those last 10 values. No problem, right?
But is that the only way? Forcing rand() to run every single time in the middle and ignoring the values, OR, can I somehow 'simulate' running the function, without actually calling the function? The reason I ask is this:
What if I want to know what the 24,419,019,005 th output of rand() is, when using a seed of 10? Whatever it is, it will always be the same value. If it's always the same value, is the ONLY way of doing it to literally call rand() 24,419,019,005 times, ignoring the values every time until you get to the iteration that you care about? Or is there some way I can say: Seed rand at 10, but then offset into the outputs 24,419,019,005 times -- i.e. PRETEND that I called rand that many times, and show me what that rand() result is, without actually calling it that many times.
Hope this makes sense. :(
Thank you for any advice!! :)