当前位置:网站首页>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
边栏推荐
- Explanation of the second I interval of 2020 Niuke summer multi school training camp
- 圆整 round 的一点点小细节
- Basemap库绘制地图
- 搭建openstack平台
- 静态成员
- Graduation project, viewing screenshots of epidemic psychological counseling system
- PM2 deploy nuxt project
- 【UDS统一诊断服务】一、诊断概述(4)— 基本概念和术语
- selenium+PhantomJS破解滑动验证2
- Dynamic creation and release, assignment and replication of objects
猜你喜欢
搭建jpress个人博客
小区房价可视化
拷贝构造函数
解决ArcGIS分区统计显示太多唯一值执行失败
【UDS统一诊断服务】四、诊断典型服务(1)— 诊断和通信管理功能单元
Graduation project, viewing screenshots of epidemic psychological counseling system
Explanation of the second I interval of 2020 Niuke summer multi school training camp
A solution to replace not in in SQL
Robocode教程5——Enemy类
类和对象的初始化(构造函数与析构函数)
随机推荐
Vscode custom comments
Rust:如何实现一个线程池?
Robocode教程8——AdvancedRobot
SQL sorts according to the specified content
GDB debugger installation and use
P1018 maximum product solution
【踩坑】Win11 WSL2 中 meld 无法正常使用问题修复
【UDS统一诊断服务】四、诊断典型服务(4)— 在线编程功能单元(0x34-0x38)
NVIDIA Jetson: GStreamer 和 openMAX(gst-omx) 插件
函数的调用过程
Export the articles written in CSDN to PDF format
【UDS统一诊断服务】一、诊断概述(3)— ISO 15765体系结构
Log4j2跨线程打印traceId
1007 go running (hdu6808) in the fourth game of 2020 Hangzhou Electric Multi school competition
1006 finding a mex (hdu6756)
【学习一下】HF-Net 训练
Robocode教程7——雷达锁定
PM2 deploy nuxt project
PM2 deploy nuxt related commands
Cf1427c the hard work of paparazzi