# Forum General How to determine the formula for a random number generator?

Post subject: Re: How to determine the formula for a random number generator?
###### ALAKTORN
He/Him
Player (104)
Tenchu: (x * 1103515245 + 12345) % 2^32 AWDS: (x+1)(4x+1) % 2^30 wait this is different. What I actually meant to say before was that cheating the RNG to 0 and advancing it 1 step allows you to figure out the formula if you’re good at maths or whatever. That’s how we found Tenchu and AWDS both.
###### solarplex
Active player (472)
I would watch the hell out of any and all videos of people who go through the process of finding RNG in different games using dissemble or other methods(with explanations). I watched a lot of sockfolder's testing on twitch which was super interesting but I havent seen anyone trying to find RNG on stream before.
Post subject: Re: How to determine the formula for a random number generator?
###### Masterjun
He/Him
Site Developer, Skilled player (1975)
Paper Mario TTYD (GCN): RNG(x+1) = (( 1103515245 * RNG(x) ) + 12345) % 4294967296 Pokemon Black 2 (NDS): RNG(x+1) = (( 6726279311198226789 * RNG(x) ) + 2531011) % 18446744073709551616
Post subject: Re: How to determine the formula for a random number generator?
###### Warp
Banned User
It uses a 64-bit RNG? Well, I suppose they wanted a maximum amount of possible variation in a Pokemon game... (Although using a LCG for randomness has a pitfall that too many programmers fall into, simply because they don't know about it. The most common way of getting a random number out of a LCG which range is smaller than the seed size is to take the value modulo the desired range. This, however, is a bad idea because the lower bits of a LCG repeat much more often than the whole period of the LCG. If you want to take advantage of the full period of the LCG, you need to take the highest bits. Or, better yet, use a higher-quality RNG that has no such problem.)
Post subject: Re: How to determine the formula for a random number generator?
###### Masterjun
He/Him
Site Developer, Skilled player (1975)
Indeed, they even calculate the starting seed of the RNG using the input & clock among other things. (RNG manipulation is cool in that game)
Post subject: Re: How to determine the formula for a random number generator?
###### Nach
Emulator Coder
I just wanted to point at that this set of constants appears near the top of the list of common parameters in the Wikipedia article I linked to in the first page. Those looking to hack RNGs should really collect all the constants there, as it's quite likely your game uses one of them.