rand() is not random
-
I pick one number by one number from numbers of 1 to 100, then submit them to 5 places (20 numbers for each). I hope results are differnent, so I use rand() and srand() to generate randomly "pick up" and "submit". but results are same always. it sounds that rand() function is not random. do you know how to solve the problem? any function which is real random? thanks
-
I pick one number by one number from numbers of 1 to 100, then submit them to 5 places (20 numbers for each). I hope results are differnent, so I use rand() and srand() to generate randomly "pick up" and "submit". but results are same always. it sounds that rand() function is not random. do you know how to solve the problem? any function which is real random? thanks
I am not sure what you mean by submit. The function srand is to seed the random number generator. I have run some tests on the rand() function that comes with the Microsoft C/C++ compiler. I find it to be an excellent random number generator. Is it a perfect one? No. The function rand() is suppose to produce a random number whose value is independent of the last value it returned. Are you saying that for two different seeds you are getting the same sequence of random numbers? If this is true, then I think there is a problem. I have a feeling that I did not help you. I also believe that if I understood your problem better, I could give you a better answer. Bob
-
I pick one number by one number from numbers of 1 to 100, then submit them to 5 places (20 numbers for each). I hope results are differnent, so I use rand() and srand() to generate randomly "pick up" and "submit". but results are same always. it sounds that rand() function is not random. do you know how to solve the problem? any function which is real random? thanks
Calling
rand()
100 times does not guarantee 100 unique numbers if that is what you mean.«_Superman_»
-
I pick one number by one number from numbers of 1 to 100, then submit them to 5 places (20 numbers for each). I hope results are differnent, so I use rand() and srand() to generate randomly "pick up" and "submit". but results are same always. it sounds that rand() function is not random. do you know how to solve the problem? any function which is real random? thanks
Please post some code. Which seed did you provide to srand ? If it is always the same, then your generated sequence will always be the same. Could that be the problem ?
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
I pick one number by one number from numbers of 1 to 100, then submit them to 5 places (20 numbers for each). I hope results are differnent, so I use rand() and srand() to generate randomly "pick up" and "submit". but results are same always. it sounds that rand() function is not random. do you know how to solve the problem? any function which is real random? thanks
-
I pick one number by one number from numbers of 1 to 100, then submit them to 5 places (20 numbers for each). I hope results are differnent, so I use rand() and srand() to generate randomly "pick up" and "submit". but results are same always. it sounds that rand() function is not random. do you know how to solve the problem? any function which is real random? thanks
includeh10 wrote:
any function which is real random
No. A purely software function can only ever be pseudo-random. The
srand
function tells therand
function where to start in its pseudo-random sequence. You need a hardware source of entropy for a real random source.Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
I pick one number by one number from numbers of 1 to 100, then submit them to 5 places (20 numbers for each). I hope results are differnent, so I use rand() and srand() to generate randomly "pick up" and "submit". but results are same always. it sounds that rand() function is not random. do you know how to solve the problem? any function which is real random? thanks
includeh10 wrote:
it sounds that rand() function is not random.
It's always been known that
rand()
, and any other computer algorithm, produces pseudo-random numbers.includeh10 wrote:
any function which is real random?
No. The problem is not with
rand()
. The problem is with how you are using it."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
I pick one number by one number from numbers of 1 to 100, then submit them to 5 places (20 numbers for each). I hope results are differnent, so I use rand() and srand() to generate randomly "pick up" and "submit". but results are same always. it sounds that rand() function is not random. do you know how to solve the problem? any function which is real random? thanks
See CryptGenRandom[^] API.
includeh10 wrote:
any function which is real random?
From the docs: The data produced by this function is cryptographically random. It is far more random than the data generated by the typical random number generator such as the one shipped with your C compiler. ... With Microsoft CSPs, CryptGenRandom uses the same random number generator used by other security components. This allows numerous processes to contribute to a system-wide seed. CryptoAPI stores an intermediate random seed with every user.
It is a crappy thing, but it's life -^ Carlo Pallini