Skip to content

Latest commit

 

History

History
18 lines (15 loc) · 342 Bytes

211005.md

File metadata and controls

18 lines (15 loc) · 342 Bytes

c++ 随机数

在 c++ 中创造一个 1- 100 内的随机数

rand

#include<iostream>
#include<ctime>
using namespace std;

int main () {
    // 添加随机数种子,利用当前时间作为种子
    srand((unsigned int)time(NULL));
    int num = rand() % 100 + 1;
    cout << num << endl;
    return 0;
}