Say if you wanted to hash the value from 2 different calls to rand() at different seeds, what would be a simple and efficient way of doing this, and is it possible to only use <stdlib.h> to accoplish this?, without useing arrays or tables to store temporary data etc.
I know its possible to write your own random() class that has this capability, but the mathematics behind it is beyond me, so I appreciate anyone who can help me implement a function that uses rand() so that it will be able to seed, seed at a different value, and reseed at the point from which it left off, etc etc etc.
Say for example, as it is, the 3rd call to rand() when seeded with 0 is not the same as the first call to rand() when seeded with 3.
I want to be able to, for example, seed with time, take 10 calls to rand(), then seed with a different value, take 10 more calls to rand(), then take the 11th call of rand() had I not reseeded.
#include <iostream>
#include <stdlib.h>
int main()
{
int start_time = time(NULL);
int num = 0;
srand(start_time);
for (int x = 0; x < 10; ++x)
{
num = rand();
cout << num << endl;
}
int elapsed_time = (start_time - time(NULL));
srand(elapsed_time);
for (int y = 0; 0 < 10; ++y)
{
num = rand();
cout << num << endl;
}
srand(start_time);
for (int z = 0; z < 11; ++z)
{//notice that this loop is recursive, which I do not want!!!!!!!!!
rand();
}
cout << rand() << endl;
return 0;
}