User blog:Kitsune-no-kamisama/Divinity, Devil, or Something Different? - Getting to Know Your Best Frenemy, the Random Number Generator.

In the citadel or on sortie, no saniwa is safe from the mighty influence of Lord Random Number Generator. Whether elliciting severe depression and verbal threats of ragequitting life, or bathing the "blessed" in the holy light of a rare-drop screen, there's just no way of telling what it's scheming. It's a fact of life. There's nothing else to it...

...Or is there?

The following exposition is courtesy of a very knowledgeable and dear friend who is a Ph.D student specializing in Physics of networks. (She will be happy to explain what that is if anyone expresses an interest in the matter.)

Without further delay, I now pass control of my laptop into her hands:


 * "A lot of people play games that have some kind of random event-- whether it's Pokemon, where you don't know what kind of 'wild ___ [is going to] appear!' or the Sims, where you don't know what type of baby your Sims family will have...or, the most relevant example here, Touken Ranbu! 


 * "Some of you who play other games may have noticed that the random events there seem more, well, random than those in TKRB. Your Sims family, for example, probably won't have six children in a row with the same features unless you're doing the type of weird stuff I'm prone to doing in my Sims games (but that's another story for another time, hahaha). So why do 5 Yamabushi sometimes drop over the course of two hours, infuriating you utterly? Why, when you're grinding levels during a special event in hopes of getting a certain sword, does it sometimes seem like you're just getting the same rare consolation-prize sword repeatedly, and not the one you want, despite both having similar probability of dropping?


 * "This is for two reasons. The first is simple probability. Probability is an average, so even if the probability of a certain sword dropping is, say, 0.01, that just means that on average he drops one out of a hundred times. This becomes more accurate as you have more events, so while he probably won't drop twice in two-hundred times, he may drop like eight or nine out of a thousand times.


 * "The second reason has to do with the mechanics of the game itself. The so-called random events in games are actually dictated by a random number generator (RNG), which is basically a bunch of code that will, on demand, spit out a number. There are a bunch of algorithms for different ways of choosing random numbers, some of which are better than others. I don't want to bore you all with the minutiae of that, since it's not super relevant, but if you're still curious, I'll point you to the RNG documentation for the programming language I use every day, MATLAB. They give a very clear explanation of several different RNG algorithms you can use:


 * RNG


 * "In most games, then, random events are implemented as follows: an event has a certain probability of happening, which is going to act kind of like an 'upper boundary'; the RNG activates and gives a number; if the number is less than or equal to that 'upper boundary' given by the probability, the event will occur. For example, let's say Suzy the Sim has a five-percent chance of setting the stove on fire when she makes dinner. The RNG gives a number, let's say 0.003, which is less than 0.05, so Suzy sets her dinner ablaze.


 * "Unfortunately, RNGs are not actually random. After a certain period of time, which is different depending on the algorithm being used, the numbers start to follow a pattern. This is called autocorrelation and can really only be avoided by building a good RNG from scratch, usually out of several other RNGs, like "2 x (random #) + sqrt(another random #) x sqrt(another random #) - (another random #)^((another random #) x 10)".


 * "The difference between TKRB and other games like The Sims or Pokemon is that TKRB is free to play. If you pay for a game, you'll probably be pretty irritated if you keep running into the same wild Pokemon or if your Sim keeps producing babies with the same unfortunate combination of their parents' traits. However, since you're not necessarily paying for TKRB, there is far less motivation for Nitroplus to put in the time and/or effort and/or money required to create a more random RNG.


 * "Now, to solutions. Really, the only solution short of hacking the game and re-coding it--which you should NOT do because, like, you shouldn't!!--is to take a break when you start noticing that the same swords are dropping or that you're repeatedly getting drops (or not getting drops) in a manner that is very, very different from what's probable. Close out of your browser, fix yourself a cup of tea or go to the toilet or pet your cat or dog or rat. Take five minutes. Restart your browser--yes, your whole browser--sign back in, and you should start to see better results!


 * Happy sword-gathering! ^_^"

'''So, there you have it! Hope this was helpful~!'''