How FNaF's RNG Broke… 3 times



-Alternate Title: Everyone is stupid except me-

TL;DW: The max value in the function used for random numbers in the game engine, Clickteam Fusion, overflows after 65,535, meaning Golden Freddy is actually running Random(34464) and Shadow Bonnie is running Random(16960). Also, because Clickteam Fusion only generates 16-bit integers, the Random Number Generator can only represent probabilities out of 65,536, which can be pretty inaccurate. Taking this into account means that Golden Freddy is actually 1/32,768 and Shadow Bonnie is 1/16,384. There was also a glitch with the game engine on Android that caused the Random Number Generator to output incorrect numbers, which made Golden Freddy impossible to encounter normally (on Android only).

Huge thanks to Folmic, Yunivers, and others for helping make this video possible; I appreciate it a ton ❤️

*Become a Taken+ member for only $0.99 (at participating restaurants):*
https://www.youtube.com/channel/UCEpYtyBLtjWmanRrW9LM5hA/join

_*Additional Notes and context:*_
*Note 1 (0:26):* _While I sort of imply that the issue with Golden Freddy’s odds is a glitch, it seems to be an intentional (or at least known) limit of the game engine. It’s an odd limit, and isn’t immediately obvious, so I don’t fault anyone for not knowing._
*Note 2 (2:55):* _You can calculate exactly what number it overflows to by doing modulo 65536._
*Note 3 (3:40):* _In order for Enemy Snowball attack damage to overflow, your health needs to exceed 65,535, which is only possible at level 13,087 or above. Because counters (including exp) are limited to 999,999,999, natural character levels are limited to below 10,000._
*Note 4 (4:32):* _We’re only interested in errors with Random(x) being out of the normal range, and Jack-O-Chica is the only one that both directly uses Random(AI) and functions below 1 AI. There are other animatronics that function below 1 AI, but they aren’t affected by this limitation._
*Note 5 (5:50):* _This bias is equivalent to modulo bias, but because the implementation actually uses a bitshift, the specific numbers that are affected are different/spread out, and the average is barely impacted._
*Note 6 (6:09):* _In this case, I obviously wouldn’t actually consider implementing rejection sampling. Changing the RNG to use 32-bit (or just using the built-in rand functions) would alleviate any significant bias._
*Note 7 (6:40):* _My phrasing of “simulating the RNG” might be concerning, but I just mean calculating the number of RNG seeds that would cause Golden Freddy/Shadow Bonnie to spawn, not simulating the RNG millions of times, which would be inaccurate._
*Note 8 (6:57):* _This was actually found before the RNG bias, but it flows best when it’s placed after it {:}_
*Note 9 (7:43):* _Woo, the actual implementation! This is an implementation of a Linear Congruential Generator (LCG) with the parameters a = 31415, c = 1, and mod 65536. I can generally consider all seeds to be equally likely because the chosen starting seed is based on your computer time in milliseconds, and there’s nothing too wrong with these particular parameters._

_One thing to notice, though, is that the period for all seeds is m/4 or 16,384. This means that all seeds can be grouped into 4 long loops. For anything as/more common than 1/16,384, there will be at least 1 chance in every group, but Golden Freddy is 1/32,768 and groups 1 and 4 do not include him. This should not impact his odds much, as he only ever checks his RNG 535 times, and the starting seed is initialized every time you enter a new frame/new night._

_This is, however, actually an issue in the modern Clickteam Fusion Windows runtime, as some error is causing it to only generate starting seeds in groups 1 and 4, and Golden Freddy wouldn’t be possible if the game was updated. This is not a problem in any other runtime, so the remasters are not affected by this, not even the Microsoft Store version, as that uses the UWP runtime._

Music Used (in order):
Mini-Golf Intro – Five Nights at Freddy’s: Security Breach _(SiIvaGunner)_ (https://www.youtube.com/watch?v=xGxvN1e4SVo)
Super Mario 64 – File Select (fakeout)
Just Add Water – Freddy Fazbear’s Pizzeria Simulator
Thank You For Your Patience – Freddy Fazbear’s Pizzeria Simulator
Title Theme (Beta Mix) – Freddy Fazbear’s Pizzeria Simulator _(SiIvaGunner)_ (https://www.youtube.com/watch?v=r6-R2GAskWo)
Title Theme – FNaF 1 – 7
Last Breath – Ultimate Custom Night
Shop – Five Nights at Freddy’s AR: Special Delivery
Credits – Freddy Fazbear’s Pizzeria Simulator

In-use throughout the video, “VHS Gothic Condensed” (https://fontstruct.com/fontstructions/show/2339876) by Spottie Leonard is licensed under a Creative Commons Attribution-Share Alike license (http://creativecommons.org/licenses/by-sa/3.0/).

Chapters:
0:00 Intro
0:24 FFPS Stat Glitch
2:31 What This Changes
5:11 Let’s Be Precise
6:53 But Wait… There’s More!
8:35 Outro

source

24 thoughts on “How FNaF's RNG Broke… 3 times”

  1. Check the description for extra notes and details, and for the list of background music throughout the video.
    There are subtitles provided, and also one (telegraphed and silent) jumpscare at 4:41.
    Any questions are welcome, but this video is the best general explanation I could create.
    FAQ:
    Q: What's MB2/Mystery Box 2 Jack-O-Bonnie?
    A: Mystery Box 2 (MB2) is a move in FNaF World that swaps out your party members with 4 random ones. Scott made a slight miscalculation, and the maximum character number was 41, which didn't even exist when the game launched. It being so rare meant it never got patched, and after update v1.2 dropped, Jack-O-Bonnie became character #41.
    Q: Why are the probabilities powers of 2?
    A: They're simplified fractions of 4/65536 and 2/65536; as the way it's setup, the probabilities of all the random stuff in Clickteam Fusion are out of 65536. They just happen to be powers of 2 though, they could've been 3/65536 or 10/65536.
    Q: Did the Android glitch also affect iOS?

    A: No, it was exclusive to Android. You can actually verify this by trying to find old videos of Golden Freddy on Android vs. iOS. It's not that hard to find people finding it on iPhone, while every video on Android just shows the 1/9/8/7 Easter egg.
    Q: Is that The Cure – Close To Me playing?

    A: Yeah? Kinda, it's a SiIvaGunner rip that uses the FFPS soundfont: https://youtu.be/r6-R2GAskWo

    Reply
  2. Nah man turns out you have to hit a triple backflip while exporting the android port to computer and fixing the code in Java and then importing it back in apk and then getting the golden Freddy Easter egg before hitting the ground to activate it

    Reply
  3. I don't know if other people just always edit it out in their videos, but a friend made me try fnaf1 the other day and in every single night I had at least one time where the screen flashed with Its Me (no golden Freddy spawn tho). So I don't know if this is normal or if there was something wrong (it scared me to hell anyway the first 2 times I got it).

    Reply
  4. Yeah I gotta say I assumed it wasn't as rare as I thought it was as a kid when I was playing it with some of my friends and we got golden freddy like 3 times in a row. I thought that it was just different cause it was the mobile port.

    Reply
  5. I just did the pizzeria sim glitch, night 1 was fine. Don’t try it in nights 2 and onwards. I’ve been sitting here for 5 minutes as my returning visitors skyrockets past 30K 😂

    Reply
  6. Wow, this is probably the worst RNG I've ever seen. Really? A 16 bit number in 2023? That wasn't even common 30 years ago. Even PS1 games use 32 bit RNG output by default.

    What's even worse is how this engine clearly must support 32 bit integers in its compiled scripting format, otherwise we wouldn't even know the original number entered was 100000.

    And then the bug on android is just icing on the cake. this is pathetic…

    Reply

Leave a Comment