Original Post
hello, I want to know how does the computer produce random numbers?
Quote:
Original post by Anonymous Poster
You can ask the user to move the mouse about for a few seconds and pick (x,y) points at regular intervals.
long holdrand;void srand(long seed){ holdrand = seed;}short rand(){ return (short)((holdrand = holdrand * 214013 + 2531011) >> 16);}Simple eh!
Quote:
Original post by iMalc
From the looks of the question, the OP just wants to know how some magical function could produce a seemingly random number?
It is typically implemented pretty much as follows.Simple eh!long holdrand;void srand(long seed){ holdrand = seed;}short rand(){ return (short)((holdrand = holdrand * 214013 + 2531011) >> 16);}
Quote:
Original post by Anonymous Poster
That is not physiologically feasible. Draw a 2D spline on your screen and I defy you to go through the very same curve again and at the very same speed. Even your own signature is not perfectly identical.
Quote:
Original post by Anonymous Poster
BTW, this is how the encryption key is generated for RIM Blackberries.
Quote:
Original post by Conner McCloud Quote:
Original post by Anonymous Poster
You can ask the user to move the mouse about for a few seconds and pick (x,y) points at regular intervals.
This is amazingly not random, actually. Many people will perform the exact same motions every single time they're asked to do so, resulting in almost identical results every time. This is highly undesirable.
CM
Quote:You unfortunately don't know what you're talking about. I didn't just pull this out of thin air.
Original post by Aryabhatta Quote:
Original post by iMalc
From the looks of the question, the OP just wants to know how some magical function could produce a seemingly random number?
It is typically implemented pretty much as follows.Simple eh!long holdrand;void srand(long seed){ holdrand = seed;}short rand(){ return (short)((holdrand = holdrand * 214013 + 2531011) >> 16);}
Not really. I think the right shift by 16 bits causes this to be a bad one!
For instance, off hand I guess that this version of rand returns numbers which will almost surely end with 0x26. Instead of taking a mod you are doing a shift. Not the same thing. Taking the lower 16 bits would probably have been better. Though i admit, your code needs more analysis to claim that this one is not a good one :-)...
I think what IMalc wanted to refer to is a Linear Congruential Generator
Quote:
Original post by iMalc Quote:You unfortunately don't know what you're talking about. I didn't just pull this out of thin air.
Original post by Aryabhatta
Though i admit, your code needs more analysis to claim that this one is not a good one :-)...
I think what IMalc wanted to refer to is a Linear Congruential Generator
This is a standard implementation of a random number generator, taken from a common runtime library. Search for the above two prime numbers on google and you'll most likely get tons of search results with variants of this prng.
The upper 16 bits are far more random than the lower 16.
I know that this is a Linear congruential generator.
Quote:
Original post by iMalc
I didn't just pull this out of thin air.
This is a standard implementation of a random number generator, taken from a common runtime library.
Quote:I'm sorry, I shouldn't have acted so defensively. I've oft heard that it isn't a terrific prng, but one seldom comes across a case where anything more random is needed (especially for a beginner). For example a particle generator animation would look indistinguishable from one with a better prng. It's only when you come to analyse where every individual droplet landed over a long period of time that you'd notice any difference.
Original post by Aryabhatta Quote:
Original post by iMalc Quote:You unfortunately don't know what you're talking about. I didn't just pull this out of thin air.
Original post by Aryabhatta
Though i admit, your code needs more analysis to claim that this one is not a good one :-)...
I think what IMalc wanted to refer to is a Linear Congruential Generator
This is a standard implementation of a random number generator, taken from a common runtime library. Search for the above two prime numbers on google and you'll most likely get tons of search results with variants of this prng.
The upper 16 bits are far more random than the lower 16.
I know that this is a Linear congruential generator.
Whoa! Slow down there pal...Sorry If I offended you. I didn't mean to.
I did say your code needs more analysis before anyone can claim it is a bad one! What I stated was my opinion.. Hence the words "I think".
Upon rereading the chapter in Knuth, in LCG's the higher order bits are more random than the lower order bits if the modulus equals the word size, which is true in this case. So taking the higher order 16 bits is right.. but this RNG is pretty bad nonetheless.
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more