This is my function:
Random(int min, int max)
{
srand(time(NULL));
return (rand() % (max-min)) + 1;
// or
return (rand() % (max+min)) + 1;
// or
return (rand() % (max-min))
// or
return (rand() % (max+min))
};
And it isn't working, if I say add Random(5, 10) it sometimes show up 15, 5, 4. I can't figure it out, because all guides say "this is the way it's suppose to be" but it doesn't work. What have I missed?
This methos is part of a class.
I've tried srand(time(NULL)) placed in:
- Not at all
- In constructor
- In method
No results.
Shouldn't rand() return a value between 0 and 1? Mine doesn't.