Random numbers

This is a discussion on Random numbers within the C++ Programming forums, part of the General Programming Boards category; I have found out a code that can give random numbers but I think this code gives a random number ...

Random numbers

I have found out a code that can give random numbers but I think this code gives a random number between 0-32767.
Could it be possible to get a random number between two values like for example: 0-30 ?

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

This is generalyl a better random number generator than rand(). It only generates random bytes, so just generat 4 random bytes into a DWORD and then apply the aforementioned &#37; 31.

And of course, you know that franse needs a better random number generator from what has been discussed so far?

And "better" is of course a matter of how you defeine "better". "good" random numbers are important if you are working on something where the quality of the random numbers have a commercial consequence.

DWORD is not a standard type in anything other than Windows.

Doing a loop of 64K for EVERY BYTE seems excessive. Is this actually a recognized method of generating random numbers, or just something you thought up yourself? There are a huge number of GOOD random number generators that have had years of research to prove that they are good, the Mersenne-Twister being one of those: http://en.wikipedia.org/wiki/Mersenne_Twister. It uses less memory and less, and only loops around for 624 iterations every 624th random number - which is about 600 * 100 times better than your code.

Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

DWORD is just a macro for unsigned int, to say 'well its only available in windows' is a bit facesious, since windows is argueably the most important operating system in existance today.

And that is a good reason, you say? Why not use a typedef of your own that equates to unsigned int? - that way, the code is genuinely portable.

And mersenne twisters are very poor quality, they repeat in reasonable time. My code will not repeat during the lifetime of the universe, not even close.

So you have evidence to say that the MT paper: http://www.math.sci.hiroshima-u.ac.j...earticles.html
that describes the initial implementation is not only wrong, but considerably wrong? According to that paper it has a period (which I take to be the point where it repeats) of 2^19937 - which is certainly considerably longer than I can expect to live. So where did they go wrong, seeing as this is a peer-reviewed paper, and implemented for MANY platforms in different languages - and all of the people that have been using it over the last 10 years are obviously not aware of this deficiency. Are you planning on to release a paper with your findings, so that we can learn what you know?

DWORD is just a macro for unsigned int, to say 'well its only available in windows' is a bit facesious, since windows is argueably the most important operating system in existance today.

Nonetheless, it is not the only operating system in actual use today, and in fact is not dominant in some areas of computing.

Originally Posted by abachler

And mersenne twisters are very poor quality, they repeat in reasonable time.

That is weird: all the literature I have read on it disagrees with you, and in fact state that the Mersenne Twister algorithms are high quality pseudo-random number generators for non-cryptographic use.

Originally Posted by abachler

My code will not repeat during the lifetime of the universe, not even close.

However, that does not prove that it is a high quality pseudo-random number generator, e.g., a generator that merely increments the previously generated number will also theoretically never repeat (for eternity), but obviously it does not have very "random" characteristics. Is this algorithm in the published literature?

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

It was developed from similar foundations, but uses different methods.

I see. What publications are available that describe it and provide analyses of its quality?

Originally Posted by abachler

It has a cryptographic strength of greater than 512K bits.

It may be due to my lack of expertise in this area, but that does not make sense to me. What does it mean for a cryptographically secure PRNG to have "a cryptographic strength of greater than 512K bits"?

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.