Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Names of the functions and variables are changed from the original code, to be more understandable to humans.
- int GatchaCalculation(int modulo) //modulo is 10000 if the game is attempting to pick rarity, and the number of possible picks if the game is attempting to pick a unit, known the rarity
- {
- unsigned int seed = getTheSeed(); //It doesn't really work like this, but let's say it just gives the seed
- if ( seed == 0 ) //If the seed is equal to 0, it would get stuck forever, between pointless operations and flat out errors. The next operations will fix this
- {
- seed = getARandomNumber(0xfffffffe)+1; //Get a random number between 0 and 2^32-2, inclusive, then add 1. This implies that the seed will be not equal to 0. It is going to be important
- saveTheSeed(seed); //Saves the seed, just to be sure.
- }
- unsigned int v3 = seed ^ (seed << 13) ^ ((seed ^ (unsigned int)(seed << 13)) >> 17);
- unsigned int v4 = v3 ^ (v3 << 15);
- seed = v4;
- /*
- v3 and v4 are doing a mixture of bitshifts and xor operations. You don't have to understand how they are made.
- Also, it shows a lot better with a example, which won't be here. After we have made all of those operations, the seed has been updated (but not saved)
- */
- unsigned int negativeSeed = 0xffffffff-seed+1;
- /*
- The easy interpretation for this is that negativeSeed is the negative representation of seed, but in a 32 bit signed int representation.
- This operation is usually used with signed int, but our variable, seed, is unsigned. This is mostly the thing that killed seed prediction.
- If seed happens to be 0, there would be an overflow because 0xffffffff-0+1=2^32, which cannot be represented in an unsigned int.
- The previous steps make the last eventuality virtually impossible.
- */
- if ( negativeSeed < seed ) //Sometimes this is true, sometimes this is false.
- negativeSeed = seed; //Look at this
- saveTheSeed(seed); //Saves the seed, and it's ready for the next use.
- return negativeSeed % modulo;
- /*
- Another new thing. negativeSeed % modulo is used as the return. But negativeSeed is not guaranteed to be the real seed.
- Let's say that after a given iteration, seed = 2, and we are looking for the rarity, so modulo = 10000. negativeSeed would be 4294967294.
- While 2 % 10000 = 2, 4294967294 % 10000 = 7294. So instead of a rare, you could have gotten a super rare during an uberfest.
- And that's it.
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement