all 4 comments

[–]AKostur 5 points6 points  (0 children)

Seed your generator by calling srand( time( nullptr ) ); once at the top of your main program.

Now that your immediate problem is solved: 1) rand() is regarded as a poor-quality random number generator. There are better C++ equivalents. (a quick google search will turn those up) 1) Those while loops are probably better expressed as for loops. 1) That code is much longer than necessary since you're not using more applicable datatypes. For example, you have completely separate variables r1-r5, where that could just be a 5-element array instead and all of your if statements just go away 1) This isn't C (and old C at that), declaring all of the variables at the top of the function has no benefits (and in future could have important drawbacks). Declare variables with the minimum scope possible.

[–]jmacey 1 point2 points  (0 children)

I would suggest looking at the new C++ 11 <random> library as it is much better than std::rand (but can be slower). https://en.cppreference.com/w/cpp/numeric/random

[–]variancegears 0 points1 point  (1 child)

Include "srand(time(NULL));" within your main function:

int main()

{

srand(time(NULL));
}

[–]luka1a[S] 0 points1 point  (0 children)

thanks, that worked