Pretty much everything about what's happening and how it works is explained in comments. Perlin noise is a gradient noise algorithm developed by Ken Perlin in 2002 to randomly generate noise that is related to eachother. It can be used in many ways, commonly used for proceedural generation but also can be used for realistic texturing and proceedural animation. Unlike a noise like white noise where every value is completely random and unrelated to eachother, perlin noise values are still random but use random vectors to make a gradient and have values be related to one another and go together smoothly.
https://adrianb.io/2014/08/09/perlinnoise.html helped me understand how perlin noise works and how to implement it and code, and thanks to @Java_Programmer for their PRNG (slightly modified) and understanding how to implement the code into scratch.