Time-appropriate greetings!
I am curently a bit stuck with trying to get a function to generate random integers in a certain range.
I looked at some tutorials and this is what I "came up with":
1 2 3 4 5 6 7 8 9 10 11 12
|
int GenerateRandomNumberInRange(int Min,int Max)
{
int tempvar;
int MaxAdjusted;
MaxAdjusted = Max - Min;
srand(1);
tempvar = rand() %MaxAdjusted;
tempvar = tempvar + Min;
return tempvar;
}
|
But when I run the function a few times, it always gives me the same number.
I know that this is a "pseudo RNG", so it will always give the same SEQUENCE of numbers, but it shouldn't just always give out 5 for example.
If the output was something like 1,2,3,4,1,2,3,4 that would make sense (same sequence), but like I said, it just gives me one number.
When I use time() as a seed and run the function in an infinite loop, the output values change every second (makes sense, because the seed changes every second).
What could I do to make this work?
I already searched a bit online, but the only things I found were related to "RNG always giving the same sequence of numbers".
So, I think I am doing something wrong here ...
Any help would be appreciated ...