Given a pseudo-random binary sequence (e.g.: 00101010010101
) of finite values, predict how the sequence will continue. Can someone please tell me the easiest way to do it? Or in case it's too difficult for someone who can barely play solitaire on its computer, can someone tell me where to get my first steps...
PS: can this technique be used to predict the colour of the next electronic roulette number (e.g.: assigning 1
and 0
to red and black respectively)?

- 12,111
- 21
- 91
- 136

- 71
- 1
- 3
6 Answers
Cryptographically secure pseudorandom number generators are intended specifically to make what you want to do impossible. In particular, they satisfy the "next bit test": given k
bits of their output, you cannot guess bit k+1
with probability greater than 1/2
.
Plain pseudorandom number generators that do not satisfy the next bit test can be attacked and in fact security vulnerabilities have been discovered in real world systems due to the choice of PRNG. In particular, linear congruential generators are known to be somewhat (or completely) predictable, and some versions of Unix random may use this algorithm. This method is quite math intensive though. If you want to go down this path a search for "linear congruential generator prediction" is a place to start.
Another attack if you are aware of the PRNG implementation is to try to determine the seed used to generate the sequence you are analyzing. The seed is sometimes based on guessable information like time of day, process ID, etc.

- 36,612
- 7
- 33
- 26
To answer the PS first: No, because roulette spins are independent events so there's nothing predictive in the historical sequence of outcomes.
The general question is hard and interesting. This website can infer a surprising number of sequences from their initial values:
http://www.research.att.com/~njas/sequences/
Note that it's for arbitrary integer sequences.
I tried it on simple patterns like {0,0,1,1,0,0,1,1,...} and it says the right thing.

- 26,430
- 45
- 154
- 229
Well, for pseudo-random sequences, the only possibility is to keep count how many of each possibility has come before. If the 1s outweigh the 0s, it's more likely that the next one will be 0. How much more likely depends on the relative occurrences of each.
Note that this won't work for true randomness since the events are independent, despite what the statisticians tell you :-)
You'll find that out (painfully) the first time you get a run of 13 reds on the table when you're using the double-on-loss method of playing roulette. In any case, the house derives its advantage from 0 (and double-0 on some tables) which are neither red nor black.

- 854,327
- 234
- 1,573
- 1,953
-
My intuitions won't let me drop the Monte Carlo falacy. The fact that black and red even out over the long time seems like at some stage you'll need a run of red to counter that run of black. Obviously intellectually I know this is a fallacy, but it's a damn cunning one. – Matt Mitchell Jun 23 '10 at 01:23
-
You're right if you assume the events are independent. But if not then there may be an obvious pattern that the statistical approach you propose will totally fail on. For example, the statistical approach will suggest 0 as the next number in {1,0,0,1,0,0,1,0,0,1,0,0,...}. Feed that to the Online Encyclopedia of Integer Sequences (see my answer) and it will correctly infer that the next number is 1. (Of course if you know that the events really are independent then the seeming pattern is a coincidence and you really should say 0!) – dreeves Jun 23 '10 at 01:29
-
It is a hard one to let go of, @Graphain. But "long time" in my mind means trillions and trillions of events, not something you can do in one night at the casino :-) Another thing you need to watch for is that the events, while independent of each other, are not necessarily independent of influence. I've seen croupiers who can place the ball in a specific quadrant reliably (and although it's rumor, I'm informed some can get it down to an eighth). That's the guy you want on your side rather than the houses (at least until he's discovered in the statistical analyses the house always does). – paxdiablo Jun 23 '10 at 01:51
-
I've seen people win based on a bias like this. I wonder if the croupier's ever get bored and just say "im going to aim number 22 all night" – Matt Mitchell Jun 23 '10 at 02:03
This is a decent question but I think if "you can barely play solitaire" it might be out of your reach right now.
You should look into picking up a basic language, and most are going to say PHP but I'm wary of recommending that to a beginner (it's pretty easy to get working though, see:XAMPP). Java is probably an "easy-to-get-running-and-work-with" language but I'm sure there's better threads on here about which language to start with (Python or something probably wins because experienced programmers love it).
By the way, your English is fine (I didn't notice you were a non-native English speaker).
Now, as for your question, if you're looking at true pattern matching. I'd be inclined to convert this idea to code:
"CURRENTPOINT" is end of first letter.
LOOP: Pick letter(s) from Start to "CURRENTPOINT"
Break the rest of your binary string into blocks of the same size.
See if these blocks all equal your picked letters.
If not, move "CURRENTPOINT" along and repeat the LOOP until you run out of letters.
If so, you have your "repeating section."
If you're just guessing that the random generator is temporarily biased, and that this bias will re-establish a baseline (balanced 0s and 1s) in the reasonably short-term then you can compare the count of each 0s and 1s and say the other is more likely based on the deviation from your baseline. However, be careful of the Monte Carlo fallacy.

- 40,943
- 35
- 118
- 185
-
-
Yeah everytime I see a "what should a noob learn" PHP gets suggested and it's tough because sure it's easy for them to deploy and so many programmers are missing web fundamentals but at the same time PHP punishes you for coding properly and gives you terrible errors as a newbie. – Matt Mitchell Jun 23 '10 at 06:50
What you need to think about is the properties of randomness, study those. For example, "Randomness runs in bunches". Compare a random sequence against a predictable sequence: you won't normally find bunches in the predictable one. To take advantage of bunches wait for the bunch. And with a little luck you will win.

- 6,661
- 7
- 48
- 63

- 1
I noticed that nobody told you about periodicity.
Pseudo-random sequence always works on mathematical operation. (until the quantic computer ^^)
An usual way to generate one is to divide two prime number (not sure it's the right word but whatever).
for instance
1/3=1.333333.....
9/7=1,2857142857142857142857142857143
Those are fairly small number and what do we notice? Periodicity.
1/3=1.3 3 3 3 3 3.....
9/7=1,2857 142857 142857 142857 142857 143
The more big is the prime number the more the sequence in that case: 3 and 142857 will be big
So if you look to a pseudo-random sequence for a long time you may find a periodicity and be able to "guess" the next number. But that could take a while.
PS: sorry for my English, I’m a bit rusty ^^

- 1,190
- 1
- 12
- 32

- 1
-
Welcome to Stack Overflow! Please give complete answers: in this case, you should provide some code, or at least an algorithm as a proof of your concept. Linking to external sources is welcome, too. – Giulio Muscarello Dec 02 '12 at 13:53
-
Also, notice that the English alphabet doesn't use "àccéntéd léttérs" ;) – Giulio Muscarello Dec 02 '12 at 13:54