13 ms·
How random can you be?
- ZoltanAK 8y agoHow 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.
- bcaa7f3a8bbc 8y agoI 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.
- onlydeadheroes 8y agoPaying for each import was the worst design decision in Python!
- chongli 8y agoWhat do you mean by this? I'm not a Python expert by any means.
- Gene_Parmesan 8y agoIt's a joke.
- boomlinde 8y agoI think it was a jocular jab aimed at the idea of "saving an import" and documenting that choice with a comment that's longer than the module import would have been.
- caiocaiocaio 8y agoTotes random.
- laumars 8y agoFun experiment but very easy to game by learning their predictions: https://i.imgur.com/O3EggFY.png 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
- hnuser123456 8y agoYep, same, here's up to 30: RRRRRRLRRRLRLRLLRRRRLLRRLRRLRL
- laumars 8y agoSo what I'm learning here is the key to beating this is not to be random at all! (this comment was meant in jest rather than as a criticism. I really enjoyed this site)
- glitchc 8y agoKeep going though. You’ll settle into a rhythm, guaranteed. Unless you keep track in your head or a piece of paper, this strategy starts to fail after about 100 entries. Long term average will be 50%, equivalent of a coin toss.
- 7Z7 8y agoDon't you only need to remember the last 5 or 6?
- Hattes 8y agoThat was my experience at first as well, but I think the point (that the page doesn't really get across) is that you should start hammering on the keys rather than methodically choosing your next input each time. I did that and saw my score take a nosedive.
- 8y ago
- deleted 8y ago[deleted]
- macintux 8y agoI did much better once I closed my eyes, at 44% correct after 130 iterations. Watching the graph completely screwed me up.
- jawns 8y agoI 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.
- throwawaymath 8y agoIf you convert Pi to base 2 you won't be penalized for those long sequences of odd numbers. Mapping the decimal digits of Pi to a parity function collapses a lot of the entropy.
- umvi 8y ago> If you convert Pi to base 2 you won't be penalized for those long sequences of odd numbers That doesn't seem correct. How do you fairly map digits 0-9 to base 2? Assuming pi has an even distribution of digits, you are going to get a disproportionate amount of 1's. There are 2 ways of mapping digits to binary: fixed width and minimal. With minimal the digits 0 and 1 require 1 bit, and 8 and 9 require 4 bits. So then 0:9 maps to (0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001). Tally it up: 15 ones, 10 zeros. That means you will be encountering 1 50% as often as 0, which doesn't seem random to me. So then let's try fixed width: 0:9 maps to (0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001). Tally it up: 15 ones, 26 zeros. That means you will be encountering 0 >60% as often as 1, which doesn't seem random to me. Also, with this scheme you can never encounter more than 4 ones in a row ("78"), which is also unrandom
- umvi 8y ago> If you convert Pi to base 2 you won't be penalized for those long sequences of odd numbers There's no way to convert pi to base 2 in your head though...
- pvg 8y agoClearly the solution is to remember pi in hex.
- nullandvoid 8y agoReminds me a little of https://www.afiniti.com/corporate/rock-paper-scissors https://www.afiniti.com/corporate/rock-paper-scissors
- friendly_chap 8y ago"Walk without rhythm and it won't attract the worm" It's harder than I expected...
- andrewla 8y agoGiven 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 https://en.wikipedia.org/wiki/De_Bruijn_sequence
- empath75 8y agothe guesser gets 14% right on that sequence, fwiw. And you can just keep repeating it indefinitely.
- w-m 8y agoOnly if you map 0=right and 1=left. Mapped the other way, 0=left and 1=right, the guesser gets it right ~43%.
- sebhtml 8y agoBy using "1" for left (lastKey = 0) and "0" for right (lastKey = 1), I get 12%. A de Bruijn sequence DB(2, k) is spelled by an Eulerian path in the corresponding de Bruijn graph, whose vertices are {0, 1}^k and where any arc (x, y) has the following property: x[2..k] == y[1..k-1]. Obviously, there are as many Eulerian paths as there are de Bruijn sequences. Each such de Bruijn sequence has a different capability at getting a good score at the game "https://www.expunctis.com/2019/03/07/Not-so-random.html" https://www.expunctis.com/2019/03/07/Not-so-random.html". diff --git a/not-so-random.html b/not-so-random.html index 48c04da..168a287 100644 --- a/not-so-random.html +++ b/not-so-random.html @@ -169,8 +169,12 @@ randomHelpFunc = function(evt) { evt.preventDefault(); //document.onkeydown = null; - for (let i = 0; i<10; i++) { - lastKey = Math.round(Math.random()); + + // db(2, 6) + var inputString = "0000001000011000101000111001001011001101001111010101110110111111"; + + for (let i = 0; i< inputString.length; i++) { + lastKey = inputString[i] == "0" ? 1 : 0; testPrediction(); updateAll(); predictNext()
- umvi 8y agoOne 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)
- snikeris 8y agoI'll remember this next time we're playing rock, paper, scissors.
- throwawaymath 8y agoTechnically you should convert Pi to base 2 before doing that, because using each decimal digit's parity collapses a lot of information in a lossy way. If your function is: f: π(k) --> δ(k) where π(k) is the kth digit of π and δ(k) = 0 if k is even and 1 if k is odd, then your function is injective. The image of every even under f is equal, likewise with the image of every odd under f. A huge amount of entropy is destroyed that way. So even if Pi could be used as a pseudorandom generator (and it actually can't be), you'd lose that property by defining an injective map from your domain of inputs to the codomain of outputs.
- CapacitorSet 8y agoWhy can't pi be used as a PRNG, and why does converting each digit to its parity lose a possible PRNG property? Sure it removes a lot of entropy, but it does so by destroying information, not from creating/overwriting memory.
- jimktrains2 8y agoPi can be as it's (thought to be) normal (all digits appear with uniform frequency), but like anything, it's how you use it. Imagine you selected a digit from pie and used it to decide rock, paper, or scissors (3 options, so let's take a digit and mod 3) 0: 0 Rock 1: 1 Paper 2: 2 Scissors 3: 0 Rock 4: 1 Paper 5: 2 Scissors 6: 0 Rock 7: 1 Paper 8: 2 Scissors 9: 0 Rock Now, let's check the frequency of each option: 0/Rock: 4 1/Paper: 3 2/Scissors: 3 Your RNG is biased towards 0 here. The same thing happens, and is very common, when people just take the system random number generator and mod it by the number of values they want. They always end up biasing the bottom section of their distribution. The common way of dealing with this is to "ignore" any number that would make the set biased. Here you would ignore 9 and you have an even distribution. So, you're playing 7 rounds of RPS and you go 3/R 1/P 4/P 1/P 5/S 9! SKIP! 2/S 6/R
- Luc 8y agoI 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.
- DJBunnies 8y agoHolds up spork.
- nprz 8y agobeat me to it ;)
- kkwteh 8y agoI 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/b81d8e599ec46a2d64b096f953a11e63 https://gist.github.com/kkwteh/b81d8e599ec46a2d64b096f953a11...
- sebhtml 8y agoYou input length is 101. If you "play" for a long time, eventually, all 64 6-grams will have occurred.
- Radle 8y agoThis 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.
- kannanvijayan 8y agoThe (napkin-sketch) model of that behaviour is interesting. I'd guess that when you are pressing 4 buttons, your "internal pseudo-RNG" is incorporating a broader scope for entropy that isn't visible to the algorithm which only "sees" the two horizontal arrows. Incidentally, I also got about the same rate (59%) of success from the algorithm when I used only the two recognized keys.
- penagwin 8y agoI just tried this out, using all 4 arrow keys lands me around 52%, just the two is 60% like you guys. This is kinda cool, our brain's RNG does better with more "mental outputs"...
- pbhjpbhj 8y agoIf you imagine you're pressing one of 4 keys and then collapse the key choice as a projection on to two keys then do you get closer to the original 4-key randomness?
- dTal 8y agoSame result. 50% with four keys, 60% with just the two. This is very interesting...
- florian_s 8y agoI tried: let left = () => captureBtnLeftFunc($.Event()) let right = () => captureBtnRightFunc($.Event()) () => captureBtnRightFunc($.Event()) setInterval(() => { console.log("Guessing"); if (Math.random() < 0.5) { left() } else { right() } }, 1000)
- __david__ 8y agoReminds 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.
- teddyh 8y agoAnd this is why you should never, ever, choose your own password. You just aren’t as random as you think you are.
- crdrost 8y agoPlease 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.
- murbard2 8y agoThe 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.
- OisinMoran 8y agoSurprised nobody has mentioned the Aaronson Oracle [0] yet. [0] http://people.ischool.berkeley.edu/~nick/aaronson-oracle/ http://people.ischool.berkeley.edu/~nick/aaronson-oracle/
- hk__2 8y agoIt’s already mentioned on the webpage.
- RegBarclay 8y agohttps://dilbert.com/strip/2001-10-25 https://dilbert.com/strip/2001-10-25
- mark-r 8y agoOne of my favorites.
- grawprog 8y agoI 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.
- expopinions 8y agoLife 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
- wongarsu 8y agoHowever your life is also influenced by quantum effects, and the possibility that uncertainty in quantum physics is based on hidden variables seems to be thoroughly ruled out. To our best understanding the entire world is just a truly random probability distribution.
- bellerose 8y agoYou can have a deterministic universe effecting our deterministic universe and where we would perceive the effects as random but isn't. It could also be impossible to measure the effects as deterministic based on our lifespan not being able to analysis the data.
- 24gttghh 8y agoRelated: http://www.levarburtonpodcast.com/ http://www.levarburtonpodcast.com/ Episode 5, "What it means when a man falls from the sky" by Lesley Nneka Arimah Perhaps there are just too many variables.
- svat 8y agoHere'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...
- munificent 8y ago> 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? Doing it in your head is hard, but if you a great memory or can write things down on paper, then you could: 1. Generate a bunch more "random" coin flips than you need and write them down. Do your best to be unbiased, but don't sweat it. 2. Start a new separate list of results. 3. Go through the original results a pair at a time. If the pair is "head, tail", write "head" in the new list. If it's "tail, head", write "tail". If it's "tail, tail" or "head, head", discard it. This is basically Neumann's "fair coin from a biased coin" trick: https://en.wikipedia.org/wiki/Fair_coin#Fair_results_from_a_biased_coin https://en.wikipedia.org/wiki/Fair_coin#Fair_results_from_a_... In theory, since you know the trick, it might influence the way you generate your initial random sequence. In practice, most of us probably aren't that smart. If you are, repeating the whole process using the results of the previous run a few times should guarantee enough complex mixing that your brain isn't clever enough to back-propagate the trick into how you generate the initial random coin flips.
- JohnFen 8y agoI can't be random. I can only be arbitrary.
- BasDirks 8y agoBy hand, 37% correct after 55 inputs.
- wwweston 8y agoApparently 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.
- irrational 8y agoI 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.
- kbaker 8y agohttps://en.wikipedia.org/wiki/Random_walk https://en.wikipedia.org/wiki/Random_walk
- mocsabnimajneb 8y agoLike, totally random ️
- iheartpotatoes 8y agoDid 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...)
- DjGilcrease 8y agodid 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).
- p1esk 8y agoI was winning for the first 300 iterations, but then by 1000th iteration it was guessing correct 57% of the time. I noticed the faster I go the easier it is to predict me.
- mark-r 8y agoOne 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.
- lucb1e 8y ago> 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...
- driftonhedgehog 8y agoI feel like it wasn’t very random. I could predict your answers to some extent after the first few.
- jvanderbot 8y agoThese 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 ...
- elihu 8y agoThis (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.
- jrochkind1 8y agoThis 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".
- dan-robertson 8y agoOne can make the algorithm harder to defeat by making it probabilistic. Eg if it will have some kind of expected next move for you to make, and this probably won’t be “definitely left” or “definitely right”, and then so long as it can get some random source (which you don’t have), it should randomly guess your next move from the probability distribution of your moves. That way it’s guesses can’t win in advance and so it probably won’t be wrong so much, and the problem of beating it becomes harder too. E.g. suppose the algorithm works as follows: 1. Let {l,r} be the numbers of times in the history we have seen a five-letter sequence with a prefix of whatever the four most recently made moves were, and a suffix of {left,right} 2. Pick r randomly between 0 and 1 3. If r > l/(l+r) (or l=r=0), guess the next move is r. You know this is the strategy so if you can calculate l and r and so make the opposite move (randomly even) and win with a probability of r/(l+r), however by making your move, you make l/(l+r) converge towards 1/2 and so your probability of winning goes to 1/2 too. I suspect the best strategy in the long run is to play randomly or to just repeat some longish cycle that includes each length five cycle an equal number of times.
- wool_gather 8y agoJust 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.
- snowsilence 8y agoA more visually illustrative implementation of the prediction mechanism can be found here: https://roadtolarissa.com/oracle/ https://roadtolarissa.com/oracle/ Both cite that same "Aaronson Oracle" as the source inspiration.
- trypt 8y agoMy 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?