rand() returns the same number each time the program is run

后端 未结 6 1790
自闭症患者
自闭症患者 2021-02-02 10:46

In this rather basic C++ code snippet involving random number generation:

include 
using namespace std;

int main() {
    cout << (rand() %         


        
6条回答
  •  别跟我提以往
    2021-02-02 11:21

    For what its worth you are also only generating numbers between 0 and 99 (inclusive). If you wanted to generate values between 0 and 100 you would need.

    rand() % 101
    

    in addition to calling srand() as mentioned by others.

提交回复
热议问题