Back to the WFC main page

CRandomNumberGenerator

$Revision: 23 $

Description

This class implements a better random number generator than the C runtime library. It is based on an algorithm provided by Guy Gascoigne - Piggford (ggp@informix.com) who got it from a generator that originally appeared in "Toward a Universal Random Number Generator" by George Marsaglia and Arif Zaman. Florida State University Report: FSU-SCRI-87-50 (1987). It was later modified by F. James and published in "A Review of Pseudo-random Number Generators." Converted from FORTRAN to C by Phil Linttell, James F. Hickling Management Consultants Ltd, Aug. 14, 1989. While in FORTRAN, it was known as the RANMAR() generator. All I did was convert it to a C++ class.

Methods

DWORD GetInteger( void )
Returns a 32-bit random integer.
double GetFloat( void )
Returns a random float between 0 and 1.
void InitializeSeed( void )
Initializes the seed value for the generator. To increase randomness, it uses a combination of the number of milliseconds the NT machine has been on and the number of free clusters on the current drive to seed the generator.
void SetSeed( DWORD new_seed )
Sets the seed to this value. You can use this if you don't like my method of seeding.

Operators

These are what makes this class cool. You can use the class as a base type.

Example

#include <wfc.h>
#pragma hdrstop

void test_CRandomNumberGenerator( void )
{
   WFCTRACEINIT( TEXT( "test_CRandomNumberGenerator()" ) );

   CRandomNumberGenerator random_number;

   int index = 0;

   while( index < 20 )
   {
      _tprintf( TEXT( "DWORD  random number is %lu\n" ), (DWORD)  random_number );
      _tprintf( TEXT( "double random number is %lf\n" ), (double) random_number );

      index++;
   }
}

API's Used

CNetworkUsers uses the following API's:
Copyright, 2000, Samuel R. Blackburn
$Workfile: CRandomNumberGenerator.cpp $
$Modtime: 1/17/00 9:10a $