当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
非参数化相机畸变模型简介
Class inheritance and derivation
Tabbar implementation of dynamic bottom navigation bar in uniapp, authority management
P1018 maximum product solution
相机标定:关键点法 vs 直接法
大学概率论与数理统计知识点详细整理
grub boot. S code analysis
selenium+webdriver+chrome实现百度以图搜图
【学习一下】HF-Net 训练
Excel打开超大csv格式数据
破解滑动验证码
爬取蝉妈妈数据平台商品数据
【UDS统一诊断服务】四、诊断典型服务(4)— 在线编程功能单元(0x34-0x38)
vs中的多字节与unicode
PM2 deploy nuxt related commands
斯坦福机器学习课程汇总
搭建openstack平台
【UDS统一诊断服务】一、诊断概述(4)— 基本概念和术语
Dynamic creation and release, assignment and replication of objects
C语言输入和输出(printf和scanf函数、putchar和getchar函数)









