由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - ask a C question about random number
相关主题
random number generator in C++Random Switch Between Two Different URLs
随机数发生器问题请教Anybody help me on these questions?
C++ rand()函数每次生成同一个数How does X Input Method work?
How to generate random number in driver (build in DDK)A try-catch problem in C++
Random number generator in C++请教一个MS Linked List的问题
C++ Q20: construction and inheritance问几个问题
help understanding code (random number)Exporting pattern rules in recursive make
Randomization of an arraySOS on xlswrite
相关话题的讨论汇总
话题: number话题: random话题: second话题: srand话题: same
进入Programming版参与讨论
1 (共1页)
s*******e
发帖数: 1269
1
I used
srand((unsigned) time(NULL));
for ( int i=0;i<5;i++)
{
rand();
}
I produce the same number at the same time period such as 5 second or 3 second
.
How can I produce a random number?
n******s
发帖数: 7
2
If you invoke this program repeatedly in a short period of time, you are going
to get the same random number sequence because you are calling srand() with
the same seed, namely the integer that is the number of seconds since midnight
1970/01/01. If you must repeatedly invoke the program, you will need to find
a way to hash up the seed value. You could try putting the program to sleep
for a second or two before calling srand().

second

【在 s*******e 的大作中提到】
: I used
: srand((unsigned) time(NULL));
: for ( int i=0;i<5;i++)
: {
: rand();
: }
: I produce the same number at the same time period such as 5 second or 3 second
: .
: How can I produce a random number?

L**********r
发帖数: 83
3
But I test it, it generates different numbers?

second

【在 s*******e 的大作中提到】
: I used
: srand((unsigned) time(NULL));
: for ( int i=0;i<5;i++)
: {
: rand();
: }
: I produce the same number at the same time period such as 5 second or 3 second
: .
: How can I produce a random number?

1 (共1页)
进入Programming版参与讨论
相关主题
SOS on xlswriteRandom number generator in C++
copy constructor问题。C++ Q20: construction and inheritance
java synchronized 问题help understanding code (random number)
python和java里面非memory资源怎么回收?Randomization of an array
random number generator in C++Random Switch Between Two Different URLs
随机数发生器问题请教Anybody help me on these questions?
C++ rand()函数每次生成同一个数How does X Input Method work?
How to generate random number in driver (build in DDK)A try-catch problem in C++
相关话题的讨论汇总
话题: number话题: random话题: second话题: srand话题: same