可能重复:
在整个范围内均匀生成随机数
C++随机浮点数
如何在c ++中生成5到25之间的随机数?
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
void main() {
int number;
int randomNum;
srand(time(NULL));
randomNum = rand();
}
Run Code Online (Sandbox Code Playgroud)