# Why is math so wrong?

Example: I managed to fail a 58% challenge 11 consecutive times. The chances for this happening are 0.00717%. I don’t think anyone is this unlucky. Something must be horribly wrong with the math in the game.
Do you have similar observations?[li]
edited by kaqqao on 9/1/2013

There are so many random rolls in this game, all day, every day, that, honestly, a pattern not far removed from tossing heads eleven times in a row is bound to pop up sooner or later.

That is how randomness works.
The chance to fail doesn’t decrease each time, you have the same chance to fail after each consecutive attempt.
But well, while the chances for that exact combination (11 times in a row) are low, consider this:
If we simplify things and assume a 50% success chance, the odds of failing 11 times in a row are the same as the odds of failing 10 times in a row and then succeeding one, or for that matter any UNIQUE combination of successes/failures.
But yes, I get it can be frustrating, I just failed a similar number of times in a row.

That’s about one chance in a hundred thousand. Do you play often? If so, how many notable patterns of failure and success with probabilities on the same order of magnitude have not happened to you? Probably, a great many. (I have runs of awful luck, too, and of implausible good fortune; somehow I’m always more inclined to rage about the former than to celebrate the latter.)

Also, I recently read that Fallen London has something like 20 000 monthly players; that’s enough to render probable pretty horrible misfortunes for a few cursèd individuals. We are all Adrift on a Sea of Misfortune.

Well, I’ll send you something nice; I may not have an Overgoat, but I am yet a gentleman whose circumstances are not entirely straitened; and is this not a charitable (if somewhat rubbery and hell-touched) age?

[quote=serguma]That is how randomness works.
The chance to fail doesn’t decrease each time, you have the same chance to fail after each consecutive attempt.
But well, while the chances for that exact combination (11 times in a row) are low, consider this:
If we simplify things and assume a 50% success chance, the odds of failing 11 times in a row are the same as the odds of failing 10 times in a row and then succeeding one, or for that matter any UNIQUE combination of successes/failures.
But yes, I get it can be frustrating, I just failed a similar number of times in a row.[/quote]

[li]
This is very very true. Many people think of any set of attempts as cumulative, and the more attempts they make, the more likely it is they will succeed. This is ostensibly valid over a large enough set of attempts, but yes – a second attempt after a first attempt has no more likelier a chance of succeeding.

I worked in a casino, and I often had to attempt to explain this type of concept to customers who saw our posted average 98% payout rate (which was true - 98 percent of the money taken in from gambling was paid out to winners) and assumed they were supposed to win twice out of 100 tries, or that if they spent \$100 they would win back \$98 of it. 98% was paid out…but not to everyone. And not every machine had a 98% payout, that was the average of the machines’ payout rates. The best way I could explain it is &quotThe casino has no memory of who you are. Every time you pull that lever you have the same chance of succeeding or failing.&quot And it’s easily possible to have a run of bad luck.[/li][li]
edited by HanonO on 9/1/2013

My ‘favourite’ current example is a specific ‘this could go either way’ that I have been unlucky on each and every of the thirteen times I’ve tried it so far. p=0.0001220703125, or around one in ten thousand - given how many separate branches and how many players there are, just not a big deal (despite being annoying!)

While I am quite familiar with the selection bias that you’re all referring to, I am not ready to believe it to be the case here, as I’ve never so far had 10+ consecutive successes in anything with probability below 85% or so. Instead, I think there’s either a hidden factor or the pseudorandom number generator used for the game could have a better implementation.
Of course, I might also just be unlucky. [li]
edited by kaqqao on 9/12/2013

[quote=kaqqao]I’ve never so far had 10+ consecutive successes in anything with probability below 85% or so. Instead, I think there’s either a hidden factor or the pseudorandom number generator used for the game could have a better implementation.[/quote]My honest response is one of the following:

[ol][li]Your luck is genuinely terrible, but this is nothing to do with Fallen London. You are being punished because you recited the Diamond Sutra with insufficient frequency in your previous lives. I urge you to walk the eightfold path, before you are incarnated as a sheep or flesh-eating toad oracle.
[/li][li]I ate a raw octopus while muttering imprecations against you (backwards and in Korean, although these things were optional, and really only done as a homage to Pink Floyd and Park Chan-wook). This allowed me to steal your luck, which however turned out to be terrible, for the reason given above. I would be grateful if you would take it back by the most expeditious means at your disposal.[/li][li]The Fallen London random number generator has been compromised by the NSA, for reasons of national security. Failbetter know this, but have of course been silenced. As evidence, I adduce the absence of references to pressure cookers or fertiliser in Fallen London, which lack, as I firmly believe, impinges on the awareness of perspicacious players every day.
[/li][li]The odds of succeeding ten times in a row on an 85% challenge are nearly one in five, and you have probably done so several times without noticing. Failbetter’s RNG is almost certainly adequate and impartial, and has not been incited against you by a rogue intern or the first gloamy gleam of a new machine malevolence.[/li][/ol]
edited by Flyte on 9/13/2013

[color=#009900]The random number generator we use is the bog-standard C# one (System.Random). We do absolutely nothing unusual with it, and there are hundreds of thousands of other applications over two decades that use it in the same way. If that maths is broken, it’s the fault of either Microsoft, God or physics. (There was a time when the first two were much more similar entities, but that time is long past.

So, I’m sorry: you’ve just been unlucky. The only thing I can add to the excellent. explanations below is to say, think of it this way: there are something like fifty million of these rolls made every month. If that didn’t throw up some streaks of appalling luck, then it would be a remarkably benign RNG. I get about one mail every two months on this: you’re not alone.[/color][li]
edited by Alexis on 9/13/2013

[quote=Alexis Kennedy][color=#009900]The random number generator we use is the bog-standard C# one (System.Random). We do absolutely nothing unusual with it, and there are hundreds of thousands of other applications over two decades that use it in the same way. If that maths is broken, it’s the fault of either Microsoft, God or physics. (There was a time when the first two were much more similar entities, but that time is long past.
[/quote]

As long as you keep the RNG state across pageloads (at least within one session), and don’t rely on it auto-initializing every time (since it, by default, seeds from something dependent on current time, which doesn’t have very good statistical properties) ;)
I have no idea how coarse that default seeding is in time (milliseconds, seconds, …) or application scope (one page, one login-logout session, entire application).

in order to do that, you have to keep your Random object in memory with an open reference, or you write your seed to the database. Neither of these things are as desirable at scale as instantiating new at run-time and letting IIS munch through your discarded objects. What does make sense is the same object for a single click. I.e. a multi-stat check on a single action. That way you avoid the risk of getting 2 objects with the same seed causing your this.next() to return the same number.

I look at the post above. I see words. WORDS. But the words. They make no sense. SENSE?

[color=#009900]In the interests of transparency I’ve pasted the relevant code snippet below. I trust this will reassure everyone involved and end the matter.[li][/color]
[color=#009900]
[/color]
[color=#009900]originalResult=Random.Next(lowerBound,upperBound+1);[/color]
[color=#009900]
[/color]

Oh, come on. That’s obviously not the real code snippet.

It’s missing the reference for the prototype sentient AI which analyses your current position and gives you the result which would be least convenient. Don’t think I don’t know about it.

I’m amazed that Alexis left out the code referencing the rat counter. And that Spacemarine9 left out mentioning being amazed that Alexis left out the code referencing the rat counter.

So, no persistent rng state - and therefore no (guaranteed) statistical properties.
(still good for when you just want unpredictability, not good if you want something to happen with a given chance).
Just because almost nobody actually understands these issues (and “everybody” claims that it’s okay this way because everybody does it that way) doesn’t mean that it’s working as intended.
Not that I claim to know how FBG intends to use its random number god.

EDIT:

This doesn’t make sense. You store the RNG state (a few (dozen?) bytes) with the rest of the player’s state (many more bytes already), so if you are repeating the same seed, you are repeating everything. If anything, it would be safer - it would close any potential hypothetical “save/load/retry” type exploits…
edited by xKiv on 9/13/2013

The player’s &quotstate&quot is a row in a database. This exists on a distinct server (more likely than not replicated to one or more others, but think of it logically as existing in one place). The &quotRNG State&quot is a system object that exists within memory on the webserver. The webserver creates this object from consulting the system clock and is able to use this object to spit out values without needing anything from the database.

This is different from a client-side game where everything is (virtual) memory. Everyone’s (web)clients get the information from the webservers who get player information from the database. A client cannot seed their own RNG or futz with the value. The closest you can get is estimate your transmission time and script your client execution to attempt to hit a certain timestamp, but as the outputs can vary across .NET frameworks, that’s not necessarily worth your time either.

Furthermore, when you scale up to handle thousands of concurrent users on the webservers, you don’t ask them to touch the database with information that does not need to be persisted.

I’m not a mathematician, so I can’t play probabilistic tennis. (Probaballistic!) It is kinda accepted though that you can trust Knuth on this one.

More details from MS: http://msdn.microsoft.com/en-us/library/system.random.aspx

I think we’ve all agreed not to talk about that after the … incident … with the … in the … with … and then the SCREAMS MY GOD THE SCREAMS you know what I mean?

And also an object (or several objects) in the server’s memory, any time it’s being actually used. If it’s never in the server’s (application) memory, it can never be used by the game.
(it doesn’t have to be there all at the same time, but each part of it has to be there at some time, except useless parts, and parts that are only useful for database-level chicanery - you generally don’t want to do your application stuff on databases, even the ones that can handle it, you can end up with very long and confusing SQL statements that way)

The important thing here is … is this a new object created every time you access a page, new object for every user session, one per server thread (and reused for many pages/sessions), one per server thread (and not reused much because the server doesn’t really reuse old threads for new requests) or one per server (and reused for everything, until somebody restarts the server)?

This is something that should really happen only once. The more times you seed from clock, the more you move from well-behaved RNG towards &quotdoesn’t do what you think it does&quot.

You have to consult the database at the start of any request (unless you store everything on session), and also at the end of most request (to update current player state). Reading one more value at the start and storing that one more value at the end won’t hurt performance that much. Bottleneck is still probably internet speed between server and browser.

AFAIK Knuth didn’t say to use rand() for probabilistic stuff, just randomization.
edited by xKiv on 9/13/2013

This is now a conversation of rather specialised interest and it’s taking over the board. Take it to PMs, folks, please! (I will say that Theus’ assumptions about performance issues are broadly correct, but I don’t want to get drawn on details.)