Random Numbers

From ASSS Wiki
Revision as of 16:38, 24 March 2005 by Cyan~Fire (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

SubSpace uses random numbers primarily in its encryption, generating prizes, and controlling doors.

The following code is used in generating the encrypted kestream, prizes, and doors:

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;
}