Hello.
I need to make a random number generator for numbers between 1 and 3.
I also need to do this using srand and rand in two separate functions.
My issue is, the srand needs to be in a non-returning function.
1 2 3 4 5 6 7 8 9 10 11
void set_seed()
{
time_t t;
time (&t);
srand (time(0));
}
int get_number()
{
return (rand()%3+1);
}
When I do this the rand doesn't seem to pick up the seed from the srand function, and just outputs the same numbers constantly.
When I change the void to an int, it seems to work great.
Am I doing something wrong here? I don't understand why it's refusing to work. :(
Thanks in advance for any help.
EDIT: Good news everyone! This function now no longer works as an int. D:
They are two separate functions outside of the main function.
set_seed is only being called once, but it seems to be ignored for no adequate reason.
Also, the pointless lines are because I have no idea how this function works, and I'm basically just copy-pasting all the different forms of time seed until I get one that works.
No success.