rand() gives same number every time?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
string randomizer(string option1, string option2, string option3, string option4)
{
string choice;
switch(rand()%5)
{
case 1:
{
choice=option1;
break;
}
case 2:
{
choice=option2;
break;
}
case 3:
{
choice=option3;
break;
}
case 4:
{
choice=option4;
break;
}
default:
{
choice="null:Error";
}
}
return choice;
}
|
it always returns option2. Why does it do this? Help please!
Are you seeding it with srand() at the start of your program?
no, how do i do that?
Topic archived. No new replies allowed.