random - Why is (rand() % anything) always 0 in C++? -


I'm having trouble rand () to work in C ++ Rand () Gives a large number when I try to use the modulo operator (%) to give it a range, it always returns to 0, no matter what?

At the beginning of the program, the random number generator does not help in ceding.

The following code works fine for me (excluding a random number of 0 1000 times each Left after running):

  #include & lt; Cstdlib & gt; # Include & lt; Ctime & gt; # Include & lt; Iostream & gt; Int main () {std :: srand (time (0)); Std :: cout & lt; & Lt; (Std :: rand ()% 1000) & lt; & Lt; Std :: endl; Return 0; }  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -