Double 20s, the problem with the dice roller

For a longer time I had suspicions about the random number generator used in Pathfinder games, but with the last situation I faced I think its very likely that my suspicions are correct.

Situation: I am at [spoiler]the approach of the Threshold[/spoiler] and my main character can only be hit by a 20 by “normal” enemies. 3 of the normal archer enemies are focus firing my main in turn based mode (that I think is important).
And not a single round goes by when my main is not critically hit by one of them. Not just hit, critically hit with a roll of two 20sm sometimes even twice a round.
Statistically this result is very unlikely, yet it happened again and again over multiple reloads.

So what happens?
First a very basic explanation of how random numbers on computers work. In fact, they don’t. Computers can’t do anything random. You put in a specific number which gets modified by other specific numbers and get out a result. Put in the same numbers and the result will always be the same.
The trick to create randomness is to make the input parameters something you don’t know or control and ensure that the mathematical function outputs a nice spread of results.

And where I think Pathfinder has problems is the input parameters. It seems to me that the state of the game map, like the position of characters, their health, etc. are used as input parameter. That means when nothing on the map moves or changes you get very similar results.
Have you ever positioned your rogue next to a chest, saved, failed and reloaded over and over again because the rogue never rolls above 5?
I have. Several times in fact. Yet when I move the rest of the party the rogue suddenly rolls high and succeeds. That is how I first got suspicious.

Two things make this problem even more obvious. Turn based mode and rapid rolls like for critical confirmations.
In turn based mode only one character moves at the time, so the game map/state does not change a lot between actions as other figures are not moving around at the same time. And when you have several rolls in rapid succession the chance for anything to change between them is low.
This is imo why you often see streaks of rolls, either all good or all bad like I see with critical confirmations in turn based mode.
I hope Owlcat will in the future go over their random function or the way input parameters are selected and improve it, especially for turn based mode by not make them dependent on the game map (I think for Wrath that is too late as it is a big change and Owlcat currently has other things to do).

Do you think Owlcat wrote their own random number generator?

Hi @Ixal

Long story short, I also made the same analysis. The game seems to ‘know’ you can’t be hit with anything other than a critical, so will increase the ‘chance’ for enemies to instant 20’s (or 19s, whatever their threat range is) which will override their real roll - that is my current theory. Also the MC will critically miss a lot more often than enemies will EVER do.

Let’s calculate an example: A long bow has a critical range of 20. Many archers in the game will have a feat (improved critical) or a spell (aspect of the falcon) that increases that to 19 - 20. This is a 10% chance of a critical hit, assuming that the archer can hit on a 19. Archers often can make a full round of attacks, let’s assume that our archer has 3 (maybe with haste, or full BAB at level 11).
Let’s assume that 2 archers focus on your main char. That’s 6 attacks. The probability to not have a critical hit in 6 attacks is 0.9^6 = 0.53. This means that the probability of having at least one critical hit per round is 47%.
Maybe this is just a lot higher than you thought?

Well, Ok, that one is real. Everybody knows that traffic lights are always red, but only for you, not for the others. So the trick is to simply not watch the combat log, then this will definitly not happen :slight_smile:

I have a screenshot where I had 6 critical misses in a row, on a nearly guaranteed hit. It sure makes the “Always a chance” mythic a lot more appealing.

1 Like

Rolling a critical threat shouldn’t be an automatic hit. Only a natural 20 should always hit, unless owlcat changed the way it works. OP said that he could only be hit on a 20 and it would only confirm on a 20.

I wonder if there’s a way to record or pull the info from the combat log after a long gaming session. If you had hours of combat log data to look at you could see how common these statistically rare events are actually happening.

Right, should have worded that a little bit more precise. Anyway, a different example calculation: 6 attacks means a probability of 1 - 0.95^6 = 26% chance that at least one is a natural 20. The point is still the same, this may simply be higher than your intuition tells you.

I would not bother. (Pseudo) Random number generators have not had a problem with generating the correct approximation to probability distributions for decades. Simple linear congruential ones get that right, especially if the target distribution is the uniform distribution for an icosaeder.
Unless you need cryptographically secure ones or other statistical properties like long term correlations are problematic for your application, you need not care.

No proof, but I suspect a lot of this is confirmation bias and would explain the repeatability as an issue with the RNG seeding.

Most enemies require a nat 20 to hit my main character, and I frequently have the protective luck ward active (opponents roll twice and take the worse result). Effectively, this is the same situation as the original post - the opponent needs a double nat 20 to hit (rather than a double nat 20 to crit).

Of course, double nat 20s should occur, on average, one every 400 attacks. I frequently let multiple gargoyles/ghouls full attack easily subjecting my MC to 15-ish attacks per round for 5 rounds or so. I don’t get hit often, and once every four combats seems reasonable.

It would be interesting if a modder could create something to track and graphically display d20 rolls - perhaps separating into various categories such as rolls made by MC, made against MC, made by companions, against companions, etc.

If said archers have the lvl 20 fighter weapon grandmaster feat, their confirmation roll is an auto 20, meaning the seed generates only half the nat 20s. Don’t know if that’s the case, though.
Still, a case of 3 rolls during one fight isn’t much for a statistical analysis :slight_smile:

It is definately not random. I know that some die-hard fans white knight owlcat and woth. But the truth is, it is not random. The higher the difficulty the higher the chances monsters will crit (hit) more often, while you will roll lower numbers.

According to nexus thread KingmakerLessRandom at Pathfinder: Kingmaker Nexus - Mods and Community the following code is used to produce random numbers in Kingmaker:

private static int D(int rolls, DiceType dice)
  int num = 0;
  while (rolls-- > 0)
      int num2 = UnityEngine.Random.Range(1, dice.Sides() + 1);
      num += num2;
  return num;

public static int D(DiceFormula formula)
  return RulebookEvent.Dice.D(formula.Rolls, formula.Dice);

I doubt they changed it.
As far as I understand from nexus thread this is an entry point for all dice rolls.
I won’t judge if it is the optimal way to generate sum of multiple rolls.
But looks good for single rolls.

At least we can test if Unity generator is ok without game decompiling or modding.

Sample to generate randoms using Unity Random
public class RandomTest
    public void RandomTestSimplePasses()
        using System.IO.StreamWriter file = new System.IO.StreamWriter("D:\\dice-rolls-d6.txt");
        UnityEngine.Random.seed = 42;
        for (int i = 0; i < 100000000; ++i) {

100K samples made on current Unity (2020.3.20f1) with seed 42:
first 100K rolls d20: d20 100k -
first 100K rolls d6: d6 100k -

This can give some idea what to expect from “simple” “unmodified” rolls =)

I’ve done some programming in Unity when trying to write my own D&D 5E game. Using the inbuilt RNG would lead to some deja vu moments as I’d replay a battle and get the same dice rolls I’d gotten the previous time. I got better results from using the RNG in System.Security.Cryptography. It can’t generate dice values directly, but you can generate one number per dice side then use the dice side that matches up to the highest value.

That’s wrong approach.
Your were probably keeping seed value for unity builtin random across reruns.
System.Security.Cryptography is for high entropy random source that can generate cryptographically strong random values. But it’s slow. However its is a good source for initial seeding for e.g. System.Random instead of time.

Unity docs states it uses xorshift128 so it’s PRNG period is 2^128. More then enough for dice rolling game.

Btw generate one number per dice will not lead to fair dice till you determine how to break ties. Microsoft gives an example how to generate fair dice using random byte source in its example for RNGCryptoServiceProvider Class (System.Security.Cryptography) | Microsoft Docs not as straightforward as many can think.

The OP misunderstands random numbers on computers a bit.

Yes, they generate their pseudorandom numbers from a seed. But the purpose of the seed is to make the generator produce different numbers on different sessions. Eg. If the generator was given a seed when you first create your character, then failure to alter the seed would just mean you’d get the same rolls on your next character. Variations in action and timing would make that impossible to actually see, though.

The seed has nothing to do with the quality / distribution of the rolls you get in a single session. That’s up to the algorithm they use.

1 Like