Category : Recently Uploaded Files
Archive   : HEADZIP.EXE
Filename : RAND.CPP

 
Output of file : RAND.CPP contained in archive : HEADZIP.EXE
//----------------------------------------------------------------------
// IMPLEMENTATION FILE (rand.cpp)
// This module exports facilities for pseudorandom number generation.
// Machine dependency: long ints must be at least 32 bits (4 bytes).
//----------------------------------------------------------------------
#include "rand.h"

static long currentSeed; // Updated as a global variable

const long MULTIPLIER = 16807;
const long MAX = 2147483647;
const long QUOT = 127773; // Quotient of MAX / MULTIPLIER
const long REM = 2836; // Remainder of MAX / MULTIPLIER

void SetSeed( /* in */ long initSeed )
//..................................................................
// PRE: initSeed >= 1
// POST: 1 <= currentSeed < MAX
// NOTE: This routine MUST be called prior to NextRand()
//..................................................................
{
initSeed = initSeed % MAX;
currentSeed = (initSeed > 0) ? initSeed : 1;
}

float NextRand()
//..................................................................
// PRE: 1 <= currentSeed < MAX
// POST: currentSeed == (currentSeed * MULTIPLIER) modulo MAX
// && FCTVAL == currentSeed / MAX
// NOTE: This is a prime modulus multiplicative linear congruential
// generator that uses the global variable currentSeed
//..................................................................
{
long temp = MULTIPLIER*(currentSeed%QUOT) - REM*(currentSeed/QUOT);

currentSeed = (temp > 0) ? temp : temp + MAX;
return float(currentSeed) / float(MAX);
}


  3 Responses to “Category : Recently Uploaded Files
Archive   : HEADZIP.EXE
Filename : RAND.CPP

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/