0

This is a general question, and not specific to a programming language.

If I use a random number generator (e.g. Math.Random() in Java), the Numbers are not really random. A common practice is to seed the numbers with the local system time to get random numbers every time the program is executed.

Now what if you seed with a really random number (for example from random.org). Will the numbers you get be real random numbers too?

Magnus
  • 1,550
  • 4
  • 14
  • 33
  • Virtually everything is ultimately deterministic. But if you can't tell the difference, what does it matter? – scottb Jul 08 '15 at 15:14
  • @scottb Well it would be more efficient to use this if it works, rather than measuring atmospheric noise every time you want a random number. – Magnus Jul 08 '15 at 15:19
  • The Java libraries have been continuously developed for over 15 years. In this matter, I would assume that the years of development and the scores of developers that have been working on these classes have done a good job. If you want non-deterministic, cryptographically strong outputs, then use the `SecureRandom` class. – scottb Jul 08 '15 at 15:25
  • @scottb Java is just an example. I just wanted to know weather seeding with a real random number makes my generated numbers non-deterministic – Magnus Jul 08 '15 at 15:33
  • 1
    While a pseudo-random sequence generated from a non-deterministic seed would still be, strictly speaking, deterministic, this would be adequate for many needs, eg. games. If your problem is in the domain of security and cryptography, it may not be. – scottb Jul 08 '15 at 15:39

4 Answers4

1

Will the numbers you get be real random numbers too?

No

You'll get non-repeatable sequences on each run, that's about it

No seeding will be able to correct pseudo-random RNG flaws. Suppose you use Linear Congruential Generator. It is well known fact, that higher dimensions points sampled by LCG will be aligned among some planes. Whatever you do with seeding this LCG, it will be still exhibiting such behavior

See https://en.wikipedia.org/wiki/Linear_congruential_generator, second picture on the right for illustration of the LCG hyper-planes effect

Severin Pappadeux
  • 18,636
  • 3
  • 38
  • 64
1

The answer is no, the resulting sequence wouldn't be any more random than any other sequence the generator is capable of producing.

Pseudo random number generators produce a sequence of values algorithmically based on some internal state. Eventually (which may be a very long time for a good PRNG!) the generator will end up in a state it has visited before because there are a finite number of states. Everything from that point on will repeat identically, since each state will inevitably lead to the same subsequent state when cranked through a deterministic algorithm. In other words, PRNGs all produce a sequence of values which eventually cycles. Java's PRNG cycles in about 248 iterations. Mersenne Twister's cycle length is about 219937—you'll never cycle through its entire state space in your lifetime, but it's still producing a deterministic sequence of values.

While the details vary from PRNG to PRNG, seeding is used to determine the initial state. Choosing a truly random seed value means that you are climbing into the deterministic cycle at a randomly selected point, but it remains a deterministic sequence from that point forward.

pjs
  • 18,696
  • 4
  • 27
  • 56
1

No.

It is not meaningful to speak of individual numbers as "random" or not. It is the sequence that is or is not random. No matter how you seed a PRNG, the sequence will be deterministic and therefore not truly random.

It is, however, the best way to seed a PRNG for uses that don't require cryptographic security like simulations and Monte Carlo integration, so it is a very good practice. Ideally, you want to seed the PRNG with as many truly random bits as the size of the PRNG's internal state.

Lee Daniel Crocker
  • 12,927
  • 3
  • 29
  • 55
0

With a pseudo-random number generator, by definition, the next number can be predicted from the previous ones. That's what pseudo-random means: the numbers are part of a deterministic sequence, they are not truly random. If you seed the PRNG with a truly random number -- which is of course an excellent idea -- you will get a different part of the PRNG's sequence each time, but the numbers you get will still be pseudo-random, not truly random.

[P.S. When I said "the next number can be predicted from the previous ones" that was a simplification; as Lee Crocker has pointed out, it's actually the internal state of the generator that predicts the next output.]

Steve Summit
  • 45,437
  • 7
  • 70
  • 103
  • That's not quite right: a PRNG is simply defined as any deterministic algorithm that produces a sequence of random-looking numbers. These are 100% predictable from the PRNG's internal state, but not necessarily predictable from a string of previous outputs. Blum Blum Shub, for example, is a PRNG in which it is NP-hard to predict the next output from previous outputs. – Lee Daniel Crocker Jul 08 '15 at 23:20
  • @LeeDanielCrocker: I like your answer. It was bugging me to talk about the randomness of a number; your point that it's the _sequence_ that's random is the key. (I'm reminded of [this comic](http://xkcd.com/221/).) – Steve Summit Jul 08 '15 at 23:35