Advertisement
Guest User

Untitled

a guest
Sep 29th, 2018
1,468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.37 KB | None | 0 0
  1. //Names of the functions and variables are changed from the original code, to be more understandable to humans.
  2.  
  3. 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
  4. {
  5.   unsigned int seed = getTheSeed(); //It doesn't really work like this, but let's say it just gives the seed
  6.   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
  7.   {
  8.     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
  9.     saveTheSeed(seed); //Saves the seed, just to be sure.
  10.   }
  11.   unsigned int v3 = seed ^ (seed << 13) ^ ((seed ^ (unsigned int)(seed << 13)) >> 17);
  12.   unsigned int v4 = v3 ^ (v3 << 15);
  13.   seed = v4;
  14.   /*
  15.   v3 and v4 are doing a mixture of bitshifts and xor operations. You don't have to understand how they are made.
  16.   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)
  17.   */
  18.   unsigned int negativeSeed = 0xffffffff-seed+1;
  19.   /*
  20.   The easy interpretation for this is that negativeSeed is the negative representation of seed, but in a 32 bit signed int representation.
  21.   This operation is usually used with signed int, but our variable, seed, is unsigned. This is mostly the thing that killed seed prediction.
  22.   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.
  23.   The previous steps make the last eventuality virtually impossible.
  24.   */
  25.   if ( negativeSeed < seed ) //Sometimes this is true, sometimes this is false.
  26.     negativeSeed = seed; //Look at this
  27.   saveTheSeed(seed); //Saves the seed, and it's ready for the next use.
  28.   return negativeSeed % modulo;
  29.   /*
  30.   Another new thing. negativeSeed % modulo is used as the return. But negativeSeed is not guaranteed to be the real seed.
  31.   Let's say that after a given iteration, seed = 2, and we are looking for the rarity, so modulo = 10000. negativeSeed would be 4294967294.
  32.   While 2 % 10000 = 2, 4294967294 % 10000 = 7294. So instead of a rare, you could have gotten a super rare during an uberfest.
  33.   And that's it.
  34.   */
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement