9 ms·
Around 15 years ago, when casual little games on Facebook were still a thing (actually when Facebook itself was still a thing), I used to play Yahtzee on the si
by anyfoo 4y ago
Around 15 years ago, when casual little games on Facebook were still a thing (actually when Facebook itself was still a thing), I used to play Yahtzee on the site while watching TV shows or whatever. It was one of the most popular games on there. For me it was something to fidget with (there was no money involved or anything, just a personal high score), so I played it a lot.
I felt more and more that dice values of specifically 1 and 6 were harder to come by than other values, so one day I sat down for a few minutes and logged the value of 100 or so dice throws. Turns out I was right, the distribution was not uniform: 2-5 were fine, but it seemed that it was twice as hard to get a 1 or a 6 compared to any other value.
I even did a chi-squared hypothesis test, because I was crazy. (And because I was studying for my statistics minor in university at the time).
Seeing the result, the problem was pretty clear, without even knowing the source code. Almost certainly, they had a random number generator giving a number in a uniform range, let's say from 0 to 1, and did something like the following to get a dice value from 1 to 6:
value = round(random()*5)+1
Do you spot the issue?
The problem is that round() rounds to the nearest integer. So any value between, say, 1.5 and 2.5 (exclusive at one end) rounds to 2, 2.5-3.5 rounds to 3, and so on. Add 1, and you have the dice value.
But the ranges for dice values 1 and 6, are only 0 to 0.5 and 4.5-5 respectively, so ranges that are only half the size.
The fix should be extremely simple:
value = floor(random()*6)+1
The crucial point being to use floor() or ceil() instead of round(), to only round towards one direction.
I wrote up exactly this in a short email to the company that made the Yahtzee game. They did not reply and just silently fixed the bug, right after my email. I was disappointed and stopped playing.
- bscphil 4y ago> I wrote up exactly this in a short email to the company that made the Yahtzee game. They did not reply and just silently fixed the bug, right after my email. I was disappointed and stopped playing. I love this. It's one of those things that's entirely intelligible to me but I imagine would be next to impossible to explain to a Martian.
- deanCommie 4y agoSame :) But here's another layer, though. What if it isn't? Our science fiction is filled with this fairly human-chauvinistic worldview where even in a hypothetical future where we are rubbing shoulders with many different alien species, many of them technologically superior to ours, some of them still admire or begrudgingly respect us for our ingenuity, spirit, some je ne sais quoi. That we're illogical and inconsistent and jealous and petty and insecure, but also humble and funny and empathetic and creative. But...we have no evidence that this would be unique about humans whether sentient intelligence is common throughout the universe or rare. In fact, it's quite possible, that this is a necessary prerequisite, side effect, or consequence of conscious intelligence. So this hypothetical martian maybe would just smile, nod and say "Ah yes, the company was embarrassed, or didn't want to risk liability, or didn't want to risk their reputation being compromised. But OP just wanted a thank you. He wouldn't have wanted money, just a 'hey thanks for finding that for us'. And it soured him on the whole experience. Been there, my new human bro, been there." edit: I wrote this before I saw the rest of the replys, and HOLY, there's a bunch of humans that don't understand why OP stopped playing.
- eastbound 4y ago> it's quite possible, that this is a necessary prerequisite, side effect, or consequence of conscious intelligence. I can’t wait for AI psychologists. AIs hired to make AIs talk about their reasonings because they are stuck in feedback loops. AIs having to be debugged. AIs being too selfish or too generous or too insecure that they keep deflating what they try to say despite being of extremely high value. AIs suddenly cracking nonsense when we need them the most under high pressure. I’m persuaded all these are required aspects of general organic intelligence.
- lucasmullens 4y agoInterestingly that Yahtzee version was rigged in the player's favor since they're more likely to get X-of-a-kind if the same numbers appear more often. Average scores probably dropped a decent bit after that fix.
- anyfoo 4y agoFor the short time that I knew about it and it was not fixed yet, I integrated it into my strategy. 1 and 6 are rare, so if for example I still needed them for something, I was inclined to make good use of 1 and 6 when they came up, instead of rerolling them for something else.
- phailhaus 4y agoYou stopped playing because they listened to you and fixed the bug for everyone?
- altairprime 4y agoThey didn’t say “thank you”, which for many humans is demoralizing.
- xen2xen1 4y agoAnd at that point he'd played the game a lot, so he probably would have quit playing anyway. Were he like me, the fun at that point was the statistics portion anyway, and he'd already found and fixed that, so it was no longer fun either.
- anyfoo 4y agoAfter I (happily!) did their work for them, a simple "thank you", or even an acknowledgment through a closed ticket, would have entirely sufficed to make my day.
- rcfox 4y agoBack when Stack Overflow was in beta, the original design was really rough, so I mocked up a suggested new design for the main page via Stylish and submitted it to them. Within a day or two, they adopted something almost identical but never acknowledged me. One could argue it was a pretty basic idea (I only spent around 15 minutes on it myself) and they probably arrived there independently, but I still like to believe that I influenced a major site's design.
- stavros 4y agoBack when reddit was good, I was a moderator of a pretty large subreddit. One April Fools' day, I decided that, as a joke, I'd edit my subreddit's CSS to show the "reddit is down" image over of the home page. I did that, and, a few minutes later, reddit was actually down. One could argue it was a coincidence, but I still like to believe that I influenced a major site's uptime. Mostly because they told me I crashed the site and asked me not to play any more jokes like that again.
- deleted 4y ago[deleted]
- marton78 4y agoHow do you know they fixed it shortly after the email? Did you keep sampling the distribution and performing chi square tests?
- anyfoo 4y agoI had the impression 1 and 6 weren’t as rare anymore (even a single game is a lot of dice throws, and I usually played several in a row and restarted a lot), so I sampled again. No chi-squared test this time, that was just for my learning, because it was obvious without.
- fuglede_ 4y agoHeh, I remember running into something similar professionally, using the .NET Framework to generate random numbers: When asked to generate random integers, it has a seemingly innocent conversion from integers to floating points and back that ends up causing significant bias on large ranges. Specifically, `Random.Next(b)` produces an integer between 0 and b − 1 by 1. taking a random integer between 0 and 2^31 − 2, 2. dividing the integer by 2^31 − 1 to get a double-precision floating-point between 0 and 1, 3. multiplying this floating-point with b to get a number between 0 and b, 4. taking the integer part of this new number to get an integer between 0 and b − 1. Do this for b = 2^31 − 1, and 50.34% of outputs are odd numbers, where you'd expect (almost) as many evens as odds. Ended up doing a bit of a write-up here: https://fuglede.dk/en/blog/bias-in-net-rng/ https://fuglede.dk/en/blog/bias-in-net-rng/ Another fun thing about their RNG was that it was apparently supposed to follow Knuth's provably useful additive PRNG which, given n − 1 randomly generated numbers, generates a new number by taking the sum of the (n − 24)'th and (n − 55)'th numbers modulo some specific number; back when I looked, Microsoft's implementation for some reason uses 34 instead of 24, probably just a typo, with the unfortunate side effect that Knuth's theoretical guarantees are out of the window.
- Stratoscope 4y ago> the distribution was not uniform: 2-5 were fine, but it seemed that it was twice as hard to get a 1 or a 6 compared to any other value. As soon as I saw that, I knew exactly what the problem was. I'm glad I was reading on a small mobile screen, so I didn't feel like I was cheating by getting a hint from the rest of your comment. Yes, voice of painful experience here! > The crucial point being to use floor() or ceil() instead of round(), to only round towards one direction. [emphasis added] Not quite. If the random() function in your language returns a value in a half-open interval like Math.random() in JavaScript or random.random() in Python, only use floor(), never ceil(). Those random() functions return a value n where 0 <= n < 1. In other words, n may be 0 but will never be 1. So floor() is always what you want for a random function like that. A somewhat related tip for anyone who implements a progress message like "nn% done". You should always use floor() for that number as well. Quite often I see a case where someone has used round() instead, or possibly ceil(). And then what happens is your notification message says "100% done" when the process is not 100% done. It makes me a little crazy when I see that. Use floor() and you won't have this problem.
- madeofpalk 4y ago> Quite often I see a case where someone has used round() instead, or possibly ceil(). And then what happens is your notification message says "100% done" when the process is not 100% done. The video game Destiny has this problem with how it displays objective percentages - it will round up, and there's a quest every now and then that shows progress as a percentage and has a high enough denominator to trigger this.
- anyfoo 4y agoYep, you're right, including ceil() was misleading of me, if not downright wrong. I technically did not specify which side the interval is open on. But practically and realistically, in pretty much any scenario it will be a half-open interval that excludes the upper bound, and you have to go out of your way to get it the other way around (at which point you probably well know yourself to use ceil() instead of floor()).