`
Jia_er
  • 浏览: 10411 次
  • 性别: Icon_minigender_2
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

C++中的随机数

    博客分类:
  • 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

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics