I cooked up this simple bit of code in hopes to exceed pseudorandom number generation maybe touch the face of true randomization:

    For[i = 1, i < 65, i++,
  seed0 = RandomInteger[{1, 22957480^3}];
  SeedRandom[seed0]; seed0 = RandomInteger[{1, 22957480^3}]];

I am concerned over the default seed value though. Anyone have a better way to generate randomness?

  • 1
    $\begingroup$ What's wrong with the default seed ("the time of day and certain attributes of the current Mathematica session")? $\endgroup$ – István Zachar Mar 7 '12 at 17:53
  • 14
    $\begingroup$ @Sinistar What you do does not perform any better that default initialization. In fact, there is a 1-1 mapping from the default seed to the seed you propose. Thus you introduced no additional randomness. $\endgroup$ – Sasha Mar 7 '12 at 18:05
  • $\begingroup$ Does anyone have an opinion on the methods offered by SeedRandom? $\endgroup$ – Sinistar Mar 7 '12 at 18:10
  • 2
    $\begingroup$ "MersenneTwister" Mersenne twister shift register generator "MKL" Intel MKL generator (Intel-based systems) "Rule30CA" Wolfram Rule 30 generator $\endgroup$ – Sinistar Mar 7 '12 at 18:10
  • $\begingroup$ @Sinistar I read your flag. Moderators cannot control how people vote, so appealing to us not to down-vote won't help. (Incidentally one of the two up-votes is mine; I thought it was a good question because of the discussion it lead to.) I suggest you add a note to the top of your question kindly asking people to stop down-voting. $\endgroup$ – Mr.Wizard Mar 20 '14 at 19:32

You cannot, by principle, get true randomness through a deterministic algorithm, no matter how sophisticated. If you need true random numbers, you'll have to collect some physical randomness. I don't know about an OS-independent way to do that, but on Linux, the pseudo-file /dev/random collects entropy from various sources.

Of course, unless you are implementing cryptography, you'll most likely not really need true randomness (and even there you generally only need it to seed the cryptographically secure pseudo-random number generator, unless you are generating an one-time pad).


Here is how you can get a truly random number:


Quantum mechanics.

You could also use Random.org which provides random numbers based on atmospheric noise:


But is atmospheric noise, really random enough for you?


To add to what @celtschk said, I've seen programs like TrueCrypt use mouse movement entropy to seed a (pseudo?)-random number generator. To get mouse input in MMA for 10 seconds, you could use something like:

mouse = {};
updateMouse[pos_] := AppendTo[mouse, pos]

I don't know much about cryptography and creating good entropy seeds, but this is the start of an approach that could be used.


I believe Mathematica is robust enough for writing a driver and the necessary image recognition software for this machine.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.