

How bad are you at generating random numbers? - RuggeroAltair

This is a fun silly game. You input 0s and 1s as random as possible.
Some algorithm tries to guess what you are going to input based on your patterns.<p>http://seed.ucsd.edu/~mindreader/<p>It is extremely hard to win without a thought strategy, almost impossible.<p>And if you want to test a sequence versus two or three word distribution this is a cool tool:<p>http://www.khanacademy.org/labs/explorations/frequency-stability
======
Wilduck
I just won with a score of 9, although I have no idea how I did it.

I'm curious how this works. I'm guessing that the underlying algorithm is
predicting based on a number of different heuristics, measuring the success of
each heuristic, and using the prediction from the most successful heuristic up
to that point. This can be a successful strategy for a Rock Paper Scissors bot
(see: <http://stackoverflow.com/a/8827797/173292>)

If it's implementing that sort of algorithm under the hood then it isn't
necessarily measuring true randomness, as there would certainly be
deterministic patterns that could beat it. Anyone have the time to type in the
binary representation of the fibonacci sequence?

~~~
RuggeroAltair
I think it creates a dictionary of n-grams. Adjusting heuristically the
probabilities the algorithm probably chooses the one with the best chances.
There is probably some assumption about the fitness function that can be tuned
to include more special cases.

Not knowing the algorithm I can't be sure, but I guess what it's showing is
that we are usually pretty bad at generating numbers, since it's hard, for
example, for each person not thinking about it, to keep the same frequency of
3-words as 000, 010, 110, 111 etc...

Your idea of using the Fibonacci series is good. I tried something similar. I
tried once implementing the integer series, :-), 0, 1, 10, 11, 100, 101... and
I won. Now with that I lose. So maybe the algorithm has been changed to take
that into account. I tried other series and I won, but I guess it could also
be because it's hard to get any significant pattern in a 100 move game when
the series are complicated. It's possible, though, that the same algorithm
would win against deterministic patterns if given enough time.

It would be interesting to try with prime numbers as well. It may be easily
hard coded as prediction, though.

------
debacle
Pretty bad, apparently. I can't seem to beat the computer, even if I generate
the random string beforehand.

~~~
RuggeroAltair
What are you using to generate the strings?

~~~
debacle
JavaScript.

~~~
RuggeroAltair
I guess JavaScript has a pretty bad random number generator. The tool I linked
does a good job at showing that. If you post a string here I'd be curious to
look at it.

In the past computers where using generators that under some particular tests
turned out to be performing really really bad.

~~~
debacle
The code I was using is here:

var random = [];

var i = 10;

while(i) {

    
    
        random.push(Math.floor(Math.random() * 2));
        i--;

}

console.log(random.join());

I was just manually doing the insertions. It lost five out of five times,
though the last time only by a very small amount.

~~~
RuggeroAltair
At a quick look in one case this function was generating more 1s than 0s.

It seems also that it generated very often a 1 after a 0 (more than twice as
many times than it generates another 0).

Now I got curious, I'll do more tests and look at the documentation for
Math.random

Certainly I won't ever use it for any important feature of a website!

EDIT: it seems that with large enough numbers it's not too bad, so I might be
able to say more after reading the documentation. At any rate using the
strings generated with the khanacademy link I was able to win few times in a
row.

