A recent project reminds me of a very simple way to generate a pseudo-random number to create a raindrop's behavior. I found that if we had a randomly initialized unsigned 32-bit seed n could loop through a pseudo-random number (C) using only 14-character multiplication tables: n*=0x9e3779b1;
Each time you apply this action, N will contain a new pseudo-random number. Very mysterious, c this operation is actually a coarse hash function of the integer multiplication method called Knuth, in an unsigned integer overflow for the moduolo operation. Moreover, for any good hash function, the result of repeated use of the hash itself produces a pseudo-random value stream in nature. Of course, this is not a good hash function, so reusing this hash itself will quickly worsen the quality of randomness, so obviously you should not use in production code-but it applies to any non-critical, such as code poems!
The magical digital 0x9e3779b1 is just a large prime number specified in the system. Technically, it can replace any other large prime. Most importantly, it must have several factors, and there is a large enough amount of information to allocate to a higher value bit when an integer overflows. This is mostly the nearest prime number 2 ^ 32/φ-Knuth Initial selection
In the water. I did some extra bad things (TM) such as using a 64-bit signed integer, using an uninitialized value as the starting value of a random seed, both of which are undefined behaviors, but fortunately gcc kindness for me still has an impact I've been looking for generating code. Antique Identification
14-character Random number generator