from Hacker News

How random can you be?

by mdp on 3/8/19, 11:48 AM with 150 comments

  • by svat on 3/8/19, 5:33 PM

    Here's a fun trick I learned from Flajolet and Sedgewick's Analytic Combinatorics (available online, page 52). I imagine it will seem incredible when tried with an actual classroom:

    > Révész in [Strong theorems on coin tossing] tells the following amusing story attributed to T. Varga: “A class of high school children is divided into two sections. In one of the sections, each child is given a coin which he throws two hundred times, recording the resulting head-and-tail sequence on a piece of paper. In the other section, the children do not receive coins, but are told instead that they should try to write down a ‘random’ head-and-tail sequence of length two hundred. Collecting these slips of paper, [a statistician] then tries to subdivide them into their original groups. Most of the time, he succeeds quite well.”

    > The statistician’s secret is [...] in a randomly produced sequence of length 200, there are usually runs of length 6 or more: the probability of the event turns out to be close to 97%. On the other hand most children (and adults) are usually afraid of writing down runs longer than 4 or 5 as this is felt as strongly “non-random”. The statistician simply selects the slips that contain runs of length 6 or more as the true random ones. Voilà!

    ----

    Obviously, the way to beat this site (or the above classroom trick) would be to use "true" random numbers. But if one doesn't have access to coins or computers, it raises the question: what is a good way to generate a long sequence of reasonably random coin flips in one's head? For example, if you've memorized many digits of pi or e or some such "believed to be normal" constant, you could use whether each digit is odd or even (or maybe even something like throw away 8 and 9, and read each remaining digit in octal to get 3 random bits). But that only gets you so far...

  • by andrewla on 3/8/19, 2:33 PM

    Given the implementation, an interesting way to cheat is to use de Bruijn sequences [1]. B(2,5) is 00000100011001010011101011011111, so using this sequence means that you will cycle through all possible 5-grams, and thus make lots of money.

    Ah, should have read more carefully -- it's using 5-grams as the base, not as the model, so really it's 6-grams, so we need B(2,6). We can try 0000001000011000101000111001001011001101001111010101110110111111

    [1] https://en.wikipedia.org/wiki/De_Bruijn_sequence

  • by crdrost on 3/8/19, 3:57 PM

    Please notice that the payoffs in this program are set up such that you will, in fact, feel cheated.

    The basis for this is that you will likely spend maybe 30-60s playing this game so you will register something between 100-200 keypresses or so. If you just click the "Randomize" button you can see the problem: a truly random input source will fluctuate over 100-200 keypresses much more than it will be biased upwards, so that after 100-200 you will probably see some run of "bad luck" by which the truly-random algorithm crashes from $1005 to $995 or so. Now if this were you, you would have stopped there with the last 5-10% being predicted perfectly, and said "okay, okay, the algorithm has learned how I behave." But it hasn't.\

    Part of this is the fallacy that people generally assume that over a large number of trials the standard deviation of a sum of random variables drops to zero -- that is true of an average but not a sum. So you have a discrete random variable which takes on the values +1.05 with probability 0.5 or -1 with probability 0.5, so its variance is basically 1.0 (off by 625 ppm but whatever) and so its standard deviation is basically 1.0 and if you sum N of these you have a standard deviation that is 1.0 √N while the mean is 0.05 N, these only equal when √N = 1.0/0.05 = 20 and thus N=400.

    So at 100-200 trials, you cannot generally expect the systematic bias from winning extra money when you are random to visibly outweigh the random noise from just randomly being wrong, you have to go to 500+ trials to really prove your mettle. But most people just won't play this thing for that long.

  • by Radle on 3/8/19, 2:54 PM

    This is interesting, i first thought I can use all 4 arrow keys, so i tried to make random movements with 4 keys.

    The program only guessed 49% of my inputs right over 100 Iterations.

    When I understood it's only two keys the program guessed correct 60% of the time.

  • by umvi on 3/8/19, 2:35 PM

    One advantage to having a couple dozen digits of pi memorized is having a psuedo random number generator at your disposal.

    Useful for generating random rocks paper scissors moves, or in this case, random directions (odd = right, even = left)

  • by kkwteh on 3/8/19, 2:53 PM

    I wrote a quick and dirty Python script that outputs a string of guesses that will beat the guesser. It keeps track of the 5-gram counters and always opts for the less-used option. If there is no less-used option it picks a random direction.

    For instance, if you input RLLRRLLLLRLLRRRLLRLLLLLLRRLRLRLLLRRRRLRRRRRRLLLRLRLRRLRRLLRRLLLRRLRRLRLLRLRRRLRLRLLLRLLRLLLLLRLRLRRR it only guesses right 34% of the time.

    https://gist.github.com/kkwteh/b81d8e599ec46a2d64b096f953a11...

  • by laumars on 3/8/19, 2:13 PM

    Fun experiment but very easy to game by learning their predictions:

    https://i.imgur.com/O3EggFY.png (0% guessed right after 15 key presses)

    Here's the sequence I used. I'd be interested if this works for other people too:

        1:  right
        2:  right
        3:  right
        4:  right
        5:  right
        6:  right
        7:  left
        8:  right
        9:  right
        10: right
        11: left
        12: right
        13: left
        14: right
        15: left
  • by __david__ on 3/8/19, 3:41 PM

    Reminds me of when I tried to give someone a fake social security number. I changed out the last four digits to something "random" but later noticed I had chosen the last four digits of my credit card. Being random is hard.
  • by murbard2 on 3/8/19, 4:17 PM

    The program collects statistics based on your previous 5 key-presses. That's one way to do it, but there's a much better, extremely elegant algorithm for quickly making predictions by averaging over a doubly exponential number of models of this form. The algorithm is called Context Tree Weighting, or CTW for shorts. Look it up.
  • by jawns on 3/8/19, 2:21 PM

    I used the first 100 digits of pi (left for even, right for odd) and it guessed correctly 49% of the time.

    By the way, within those first 100 digits, there are multiple occurrences of even or odd sequences that go past the 5-gram level.

    Within the first 1000 digits of pi, there is one 11-digit sequence of odd numbers, which you will lose money on.

  • by bcaa7f3a8bbc on 3/8/19, 2:03 PM

    I tried...

        $ python3
        >>> # not using os.urandom to save a import...
        >>> rng = open("/dev/urandom", "rb")
        >>> "{0:08b}".format(rng.read(1)[0])
    
    And act accordingly, soon the correct rate approaches 50% as expected.
  • by OisinMoran on 3/8/19, 4:24 PM

    Surprised nobody has mentioned the Aaronson Oracle [0] yet.

    [0] http://people.ischool.berkeley.edu/~nick/aaronson-oracle/

  • by RegBarclay on 3/8/19, 4:47 PM

  • by irrational on 3/8/19, 6:54 PM

    I had a number generator randomly generate lists of 0 or 1s. 0 was left and 1 was right. I did this 500 times. It was able to guess the number entered 49% of the time. The balance never went below $1000. The interesting thing is the graph when through a cycle. It started out at $1000, climbed to $1030, dropped back to about $1000, then climbed back to about $1030. It was on its way back down again when I stopped. I'm tired of playing the game, but I wonder if the cycle would've continued and if there is an explanation for the cycle.
  • by nullandvoid on 3/8/19, 2:27 PM

  • by lucb1e on 3/8/19, 11:06 PM

    > I added three custom metrics/events in google analytics to collect statistics on correct guesses after 100, 200 and 500 inputs. If you’d rather not be counted, please load the html file from my github repository instead.

    I'm happy to participate in such statistics so I don't need that HTML file, but I'm not okay with sending it to some third party that then tracks a whole lot of other things as well. So Google Analytics is blocked as always; I'm sorry that I couldn't submit my 52% score...

  • by jrochkind1 on 3/9/19, 1:22 AM

    This is fun an interesting.

    I tried using an actual random number generator to generate inputs, just to verify with my eyes that, as expected, the computers guess rate hovered around 50%, and didn't get more than 5% off usually. (I realize it _could_).

    I tried picking a 'random' (knowing surely I'll still have unconcious patterns) number 1-5, and then doing that many lefts, pick another number, that many rights.

    That got me a really good percentage (computer was only around 30% right) up to ~40 or so iterations. But didn't last, eventually it got to around 50% or so as usual, and then I started to lose.

    It would be interesting, if knowing the algorithm the guesser is using, if you could devise an algorithm to defeat it, and "win" lots of money from the "bank". I mean, I guess, the obvious thing to do, if you had the algorithm the guesser was using, you could just run it on your own past input, and then always pick next whatever the opposite of what it would pick is. It seems like that would have to work, and that it couldn't possibly work, heh. This becomes an interesting illustration of... something or other computer science-wise, it reminds me of Godel Escher Bach or something.

    What this whole thing makes me think of is surveillance. Say, in an old detective thing, trying to "lose a tail" by making "random" turns. In our society of increasingly universal surveillance, _plus_ computers analyzing the data (and you don't know the exact algorithms being used)... there's probably no way to "lose the tail".

  • by DJBunnies on 3/8/19, 2:49 PM

    Holds up spork.
  • by florian_s on 3/8/19, 3:05 PM

    I tried:

      let left = () => captureBtnLeftFunc($.Event())
      let right = () => captureBtnRightFunc($.Event())
      () => captureBtnRightFunc($.Event())
        setInterval(() => {
          console.log("Guessing");
          if (Math.random() < 0.5) {
              left()
          } else {
              right()
          }
      }, 1000)
  • by teddyh on 3/8/19, 3:43 PM

    And this is why you should never, ever, choose your own password. You just aren’t as random as you think you are.
  • by mark-r on 3/8/19, 10:52 PM

    One of the less interesting things I've done in my life is memorize a large number of digits of pi. An interesting thing I've discovered is that I can recite those digits faster than you can make up random digits without an obvious pattern. The brain is optimized for patterns, not randomness.
  • by snowsilence on 3/9/19, 5:42 AM

    A more visually illustrative implementation of the prediction mechanism can be found here: https://roadtolarissa.com/oracle/

    Both cite that same "Aaronson Oracle" as the source inspiration.

  • by wool_gather on 3/9/19, 6:23 PM

    Just to test my opponent's predictions, I wrote a quick script using a real CSPRNG to give me left/right instructions. As expected, after a hundred moves I was way ahead.

    The interesting part was this: I had the script just run a loop with a short delay between outputs. I started with a little under a second, and my brain/fingers kept trying to anticipate the next element. Often incorrectly, making my input predictable by the site. My fingers were just twitching to press a key.

    In order to "win", I had to set the delay to 1.2 seconds, physically lift my fingers off the keyboard, and spend a little bit of effort reading each choice to make sure that I was actually following the real random instructions.

    My brain just struggled to cope with the lack of pattern.

  • by grawprog on 3/8/19, 5:13 PM

    I found it interesting to go at it randomly myself for about 100 iterations or so, the accuracy hovered around 55%. Then I started flipping a coin to make my choice, the accuracy started dropping pretty quickly, I got it down to 43% before i got bored.
  • by trypt on 3/9/19, 11:28 AM

    My method was to close my eyes then open them somewhere "random" on my screen and the first letter my eyes focused on, I checked whether it was a low (left) or high (right) letter. I'm aware that the distribution isn't this simple but that's what I used. This worked okay for a while and the machine was only predicting me at 43%, then I tried using just my brain and it started winning.

    A person good at mental arithmetic could memorize a small-state PRNG and get good results but I couldn't personally do this. I wonder if this has any strategic advantages in any areas of life. Maybe poker?

  • by iheartpotatoes on 3/8/19, 8:20 PM

    Did anyone else find this depressing? I realize the payoff is set up to make you feel cheated (see "crdrost" below), but it had a more existential impact on me until I tried using /dev/urandom parity and after 500 presses it was still within the margins described. I feel like there's a psychology experiment under the hood here... (And also wonder what kind of exciting behavior data unrelated to the "game" that the webdev captured! e.g., average play time, average win during playtime, # of times the B(2,6) showed up, # times Pi parity showed up, etc...)
  • by elihu on 3/9/19, 12:06 AM

    This (or some variation) could be an interesting competitive sport. Especially if the "guesser" algorithm was smarter, or if the guessing is done by your opponent.
  • by wwweston on 3/8/19, 6:44 PM

    Apparently I can be reasonably random -- I decided to map the length of the words mod 2 for the first three paragraphs he wrote on the page to the right (0) and left (1) arrow keys. After three paragraphs, the algorithm had 50% of my motions correct (as good as a coin flip!), and I had a positive balance. :)

    Flaw in my plan: I don't know if the word length distribution for most english texts (much less a given writer) is biased.

  • by Luc on 3/8/19, 2:37 PM

    I remember playing this game on the Commodore 64 (or perhaps VC-20) in the eighties. Can't find it now but it was probably a BASIC program.
  • by macintux on 3/8/19, 2:20 PM

    I did much better once I closed my eyes, at 44% correct after 130 iterations. Watching the graph completely screwed me up.
  • by jvanderbot on 3/8/19, 11:40 PM

    These bots are somewhat easy to beat with complex repeating sequences that are not biased over the long term.

    e.g. L,R,LL,RR,LLL,RRR, and if it starts guessing right enough, reset or reverse.

    Then, it ends up being closed loop two armed bandit ...

  • by DjGilcrease on 3/8/19, 9:41 PM

    did not seem that hard I did 106 iterations and it guessed correct 35% of the time. Maybe over more iterations I would have gotten less random (due mainly to boredom).
  • by ZoltanAK on 3/8/19, 1:56 PM

    How far are you supposed to go to get the 57% average? At first it had some success, but after 100+ presses its guesses were correct only 49% of the time.
  • by friendly_chap on 3/8/19, 2:30 PM

    "Walk without rhythm and it won't attract the worm"

    It's harder than I expected...

  • by JohnFen on 3/8/19, 5:50 PM

    I can't be random. I can only be arbitrary.
  • by BasDirks on 3/8/19, 6:02 PM

    By hand, 37% correct after 55 inputs.
  • by driftonhedgehog on 3/8/19, 11:07 PM

    I feel like it wasn’t very random. I could predict your answers to some extent after the first few.
  • by expopinions on 3/8/19, 5:27 PM

    Life is anything but random. It is nothing but a collection of actions and outcomes, both of which are tightly coupled and definitely connected.

    Let's take a simple example: you had an important meeting at 9 am but since you were stuck in traffic, you were late by 10 mins.

    The final outcome can be clearly explained by actions that directly or indirectly led to them. May be there was an accident causing the traffic jam. May be you woke up 10 mins late than usual thereby getting caught in rush hour traffic. May be the cab you took to work, arrived late at your destination cause he woke up late.

    All of the above are totally controllable actions, albeit not in your direct control. Hence the feeling that life is random. Because none of us have any control over the outcomes of the actions of others, who subtly influence our lives on a daily basis.

    Think of it this way: our life is intertwined with the lives of others in one way or the other. From the cab driver who drives us to work to our loved ones who shatter our hearts, their actions influence us, some more than the others, but influence us nonetheless.

    It's a complex equation, with a whole lot of variables, most of which are beyond our control and unknown and the solution to this equation is the outcome of an event.

    I believe that if one knew the values to all the variables at any given point of time, then one would be able to solve the equation with precision

  • by caiocaiocaio on 3/8/19, 2:04 PM

    Totes random.
  • by mocsabnimajneb on 3/8/19, 7:34 PM

    Like, totally random ️