开发者

How to get really random number? [duplicate]

This question already has answers here: Closed 12 years ago.

Po开发者_JAVA百科ssible Duplicates:

Understanding “randomness”

Fastest implementation of a true random number generator in C#

Hello. Function:

Random rand = new Random();
rand.Next()

It gives pseudo random numbers based on time in seconds. How to get really random numbers? I mean totally random not based on system time and some algorithm. Like, when you drop a cube you got really random number, not based on time and any algorithm.

What do you think about using short sample from mic or time between mouse position change?


Put a cat in a box with a bottle of poison, which will be released when a single atom of a radioactive material decays. Come back in one hour and open the box. If the cat is dead, use 0 as a random bit in your program. If it is alive, use 1.

Repeat with as many cats and boxes as is necessary.


you could use a service such as random.org


Ask the user to hit the spacebar a few times. Use the time in microseconds between keystrokes to seed your random number generator.

(or better, use the remainder of the time in microseconds mod 256 microseconds to eliminate any human periodicity. So each keypress gives you 1 random byte, use the appropriate number of strokes to seed your generator)


Most programming random functions are based on mathematical algorithms. There are random numbers generators, that use wave noises in air (from space radiation), but they're hardware based.


For that, you would need a hardware random number generater.

A good-enough-for-most-cases substitute for this is measuring the timing of "hardware events" such as user input or network activity.

On Linux, the /dev/random device produces bytes based on this method.


I would recommend you:

True Random Number Generators (TRNGs)

http://www.random.org/randomness/

That will point you in the right direction!


It's very difficult to get really random numbers. PRNGs are, after all, in some sense predictable. But it's much more difficult to correctly build a random number generator based on a physical source; most random sources don't produce real random bits all that fast, and it's hard to tell whether you've made a bad blunder. A good PRNG is better for virtually all intents and purposes.

(Only use a high-quality PRNG if you need one, as they're much slower, and make sure you use the right kind if you do: a PRNG designed for crypto is not the same as one designed for Monte Carlo simulation – crypto PRNGs make sure every bit is hard to guess, whereas MCSim PRNGs make sure that spectral properties are good – and most other uses for PRNGs just want them to not be cruddy and to be fast; the standard library one is usually good enough there.)


http://www.entropykey.co.uk/


You could use the System.Security.Cryptography.RNGCryptoServiceProvider.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜