Difference between revisions of "Random Numbers"
From ASSS Wiki
Mine GO BOOM (talk | contribs) m (Reverted edit of Zc321, changed back to last version by Cyan~Fire) |
|||
Line 1: | Line 1: | ||
− | + | [[SubSpace]] uses random numbers primarily in its encryption, generating [[prize]]s, and controlling [[door]]s. | |
+ | |||
+ | The following code is used in generating the encrypted keystream, prizes, and doors: | ||
+ | <pre> | ||
+ | #define MULT_C 0x834E0B5F | ||
+ | #define DIV_C 0x1F31D | ||
+ | |||
+ | DWORD SS_RNG(DWORD seed) | ||
+ | { | ||
+ | DWORD nseed, temp; | ||
+ | |||
+ | temp = (MULT_C * (unsigned __int64)seed) >> 32; | ||
+ | temp = (temp >> 16) + (temp >> 31); //aka the sign bit | ||
+ | |||
+ | nseed = (seed % DIV_C) * 16807; | ||
+ | nseed -= (temp * 2836); | ||
+ | nseed += 123; | ||
+ | |||
+ | if (!nseed || nseed > 0x7FFFFFFF) | ||
+ | nseed += 0x7FFFFFFF; | ||
+ | |||
+ | return nseed; | ||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | [[Category:Game Intricacies]] |
Latest revision as of 02:53, 30 November 2005
SubSpace uses random numbers primarily in its encryption, generating prizes, and controlling doors.
The following code is used in generating the encrypted keystream, prizes, and doors:
#define MULT_C 0x834E0B5F #define DIV_C 0x1F31D DWORD SS_RNG(DWORD seed) { DWORD nseed, temp; temp = (MULT_C * (unsigned __int64)seed) >> 32; temp = (temp >> 16) + (temp >> 31); //aka the sign bit nseed = (seed % DIV_C) * 16807; nseed -= (temp * 2836); nseed += 123; if (!nseed || nseed > 0x7FFFFFFF) nseed += 0x7FFFFFFF; return nseed; }