- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
随机函数rand和srand的用法(The use of random functions Rand and srand)
随机函数rand和srand的用法(The use of random functions Rand and srand)
The use of Rand and srand
We need to have an overall view of the Randsrand: srand initializes the random seed, Rand produces random numbers, the following will detail.
Rand (producing random numbers)
Header file: #includestdlib.h
Defining functions: int, Rand (void)
Function specification:
Because of Rands internal implementation is to use a linear congruential method, he isnt really random, but because it is a particularly long period, so there is a certain range can be regarded as random, (rand) will return a random value in the range of 0 to RAND_MAX. Before calling the function to generate a random number, you must first use srand () to set the seed of the random number. If you do not have a random seed, Rand () will automatically set the random number when calling, and the seed will be 1. Rand () produces pseudo random numbers, which are the same every time they are executed. To differ, initialize it with different values. The initial function is srand ().
Return value:
Returns a random integer value between 0 and RAND_MAX. The range of RAND_MAX is at least between 32767 (int), that is, double byte (16 digits). If using the unsigned int, the double byte is 65535, and the four byte is an integer range of 4294967295.
0~RAND_MAX the probability of each digit being selected is the same.
Example:
Generates a random value of 1 to 10 / between between, this example is not set seed of random numbers, random number generation please refer to complete
(srand).
#includestdlib.h
(main)
{
Int, I, j;
For (i=0; i10; i++)
{
J=1+ (int) (10.0*rand () / / (RAND_MAX+1.0));
Printf (%d, J);
}
}
Execute:
948810248, 36
948810248 / 36 again still generate random numbers the same
Srand (set random number seed)
Header file: #includestdlib.h
Defining functions: void, srand (unsigned, int, seed);
Function specification:
Srand () is used to set rand () the seed of random numbers when generating random numbers. The parameter seed
您可能关注的文档
- 长虹遥控器与整机型号对照表(Changhong remote control and machine model comparison table).doc
- 长螺旋钻孔灌注桩在复杂地层中的应用研究(Study on Application of long spiral bored pile in complex stratum).doc
- 长虹彩电iic总线维修状态的进入(Changhong color TV IIC bus maintenance status access).doc
- 长螺旋钻杆cfg桩施工方案(Construction plan of long spiral drill pipe CFG pile).doc
- 长钢9#高炉喷煤系统的优化(Optimization of steel 9# blast furnace system).doc
- 长镜头(Zoom lens).doc
- 长白山人参药用及吃法_自由人(Changbai Mountain ginseng medicinal and eat _ free).doc
- 长隆3日自助游攻略(Long long 3 self-help travel Raiders).doc
- 长隧道贯通测量方案(Long tunnel holing through survey plan).doc
- 长高秘诀(Tall Secrets).doc
- 隆回县高平镇的风土人情(The local conditions and customs of Gaoping town of Longhui County).doc
- 随读语音朗读(Reading aloud with reading).doc
- 陶瓷工艺问答(Ceramic technology Q & A).doc
- 随机对照双盲(Double blind randomized controlled trial).doc
- 随身听手册-247(Walkman manual -247).doc
- 隐入时尚潮流的俄罗斯第一夫人(Russia's first lady in fashion).doc
- 隐式类型的局部变量(c# 编程指南)(Implicit type of local variables (c# Programming Guide)).doc
- 隐形广告作业(Invisible advertising).doc
- 除草剂的作用原理.doc
- 隐形眼镜保养十二招(Contact lens maintenance twelve strokes).doc
最近下载
- 2023年外贸单证实务试卷题库和答案.doc VIP
- 消防安全重点单位消防档案.docx VIP
- 考前必备2025年四川省巴中市公务员省考公共基础知识测试卷(含答案.pdf VIP
- 教学课件:《思想政治学科教学新论》(第二版)刘强.ppt
- 2025云南怒江州福贡县义务教育教师专项招聘65人笔试备考试题及答案解析.docx VIP
- Unit 3 课时5 Word power(课件)-2025-2026学年八年级英语上册(译林版2024).pptx
- DB44/T 2457-2024地质灾害自动化监测规范.docx
- 流程制度文件评审制度及表单.docx VIP
- 2025年职业学院专任教师辅导员招聘考试笔试试题(含答案).docx VIP
- 基于BIM技术的铁路施工管理与协同方案研究.pptx VIP
文档评论(0)