C++中的随机数_C/C++_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > C/C++ > C++中的随机数

C++中的随机数

 2012/6/11 0:14:22  Jia_er  程序员俱乐部  我要评论(0)
  • 摘要:1.rand()functionheaderfile:cstdlibtoobtainarandomintegerbetween0and9,userand()%10Infact,thenumbersproducedbyrand()arepseudorandom,i.e.itproducesthesamesequenceofnumberseverytimeitisexecutedonthesamesystem,becausethealgorithmusedbytherand(
  • 标签:c++

1. rand() function

?

  • header file : cstdlib
  • to obtain a random integer between 0 and 9, use rand() % 10
  • In fact, the numbers produced by rand() are pseudorandom, i.e. it produces the same sequence of numbers every time it is executed on the same system, because the algorithm used by the rand() function uses a value called the seed to control how to generate the numbers. By default the seed value is 1.?
2. srand(seed) function?
  • header file : cstdlib
  • function : to change the seed?
  • srand(time(0)) : to ensure that the seed value is different each time you run the program

?

发表评论
用户名: 匿名