📜  C++ 代码示例中的 rand

📅  最后修改于: 2022-03-11 14:44:45.079000             🧑  作者: Mango

代码示例3
version1 = std::rand() % 3; // it is in the range from 0 to 2 // 0 1 2
version2 = std::rand() % 5 + 2; // it is in the range from 2 to 6 // 2 3 4 5 6
version3 = std::rand() % 3 + 10; // it is in the range from 10 to 12
//first number is how much digits it will go second number is the digit it 
//starts on (including that digit)

//negative
version4 = std::rand() % 11 - 12; // it is in the range from -2 to -12