Is it possible to predict the next number in a num

2019-01-25 16:37发布

问题:

With programming, it is never "random". Even the random generator uses an algorithm to predict a random number. But, if knowing the method of generation, is it possible to, let's say predict next 5 numbers that will be generated?

回答1:

Yes, it is possible to predict what number a random number generator will produce next. I've seen this called cracking, breaking, or attacking the RNG. Searching for any of those terms along with "random number generator" should turn up a lot of results.

Read How We Learned to Cheat at Online Poker: A Study in Software Security for an excellent first-hand account of how a random number generator can be attacked. To summarize, the authors figured out what RNG was being used based on a faulty shuffling algorithm employed by an online poker site. They then figured out the RNG seed by sampling hands that were dealt. Once they had the algorithm and the seed, they knew exactly how the deck would be arranged after later shuffles.



回答2:

Assuming a deterministic algorithhm. Create two identical random number generators. Ask the first one what the second one will produce next -- 5 times.



回答3:

The vast majority of "random number generators" are really "pseudo-random number generators", which means that, given the same starting point (seed) they will reproduce the same sequence. In theory, by observing the sequence of numbers over a period of time (and knowing the particular algorithm) one can predict the next number, very much like "cracking" an encryption.

The time/effort required to do this will vary greatly depending on the specific algorithm, of course. RNGs that are "cryptographic" will be very much harder to predict than your garden-variety RNG. But for most uses of random numbers this sort of predictability is not a problem.