-
Archives
- August 2010
- July 2010
- December 2009
- August 2009
- July 2009
- June 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- September 2008
- July 2008
- June 2008
- May 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
-
Meta
Tag Archives: c
srandom 与 random
今天看了看这两个函数的manpage,srandom 的作用是为random 做个种子,默认random生成的数是以srandom(1)为种子的。所以,虽然random 生成的数好像没什么规律,但每次生成的数都是一样的。如果想要改变这个所谓的“随机数”,就要再说srandom生成一个新的种子,比如srandom(2),不过这样做太麻烦了,先拿srandom(time(0))充个数吧。 #include <stdlib.h> #include <stdio.h> int main() { srandom(time(NULL)); printf(“the number is %ld\n”, random()); }