当前位置:网站首页>Generate random number
Generate random number
2022-04-23 06:36:00 【*Flowers bloom on the street】
Generating random numbers requires rand() function , This function requires a header file stdlib.h
If only rand() function , The generated random number is pseudo-random number , because rand() Function before generating a random number , The seed of generating pseudo-random number sequence provided by the system is required ,rand Based on the value of this seed, a series of random numbers are generated . If the seed provided by the system does not change , Every time you call rand The sequence of pseudo-random numbers generated by function is the same . If you want to generate different random numbers every time , Need to change random seed , Time can be used to change the random seed of the system .
int rand_()// Generate random numbers
{
time_t ts;
unsigned int n = time(&ts);// Acquisition time
srand(n);// Initialize random seed
int num = rand() % 100 + 1;// Random number range 1—100
return num;
}
版权声明
本文为[*Flowers bloom on the street]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230547207248.html
边栏推荐
猜你喜欢
scikit-learn sklearn 0.18 官方文档中文版

clion安装教程

文件查看命令和用户管理命令

Graduation project, curriculum link, student achievement evaluation system

【UDS统一诊断服务】三、应用层协议(1)

【UDS统一诊断服务】二、网络层协议(1)— 网络层概述与功能

ArcGIS license错误-15解决方法

【UDS统一诊断服务】四、诊断典型服务(6)— 输入输出控制单元(0x2F)

Cross domain issues - allow origin header contains multiple values but only one is allowed

【UDS统一诊断服务】四、诊断典型服务(4)— 在线编程功能单元(0x34-0x38)
随机推荐
Rust 中的指针:Box、Rc、Cell、RefCell
四元数乘法
pyppeteer爬虫
基于QQwebAPI 查询昵称和头像的爬虫
Friend function, friend class, class template
利用文件保存数据(c语言)
Flask操作多个数据库
C语言循环结构程序
Completely clean up MySQL win
Common shortcut keys of IDE
爬取彩票数据
GDB debugger installation and use
Linux 用rpm的方式安装mysql(超简单)
对象数组与对象指针
clion安装教程
Solution to the trial of ycu Blue Bridge Cup programming competition in 2021
ArcGIS表转EXCEL超出上限转换失败
Basemap库绘制地图
渔网道路密度计算
【UDS统一诊断服务】一、诊断概述(4)— 基本概念和术语