random.c File Reference

Abstracted interface to a random number generator. More...

#include <stdlib.h>
#include <SDL.h>
#include <time.h>

Include dependency graph for random.c:

Go to the source code of this file.

Functions

void RandInit ()
 Initalizes the random number generator, or opens access to an existing one.
Uint32 RandNum ()
 Obtains a random number.
void RandUninit ()
 Uninitalizes the random number generator.

Variables

static FILE * urand = NULL
 A file handle used to access a random number device run by the operating system.


Detailed Description

Abstracted interface to a random number generator.

Author:
Jeff Jackowski (jeffj@ro.com)
Copyright (C) 2007 Jeff Jackowski

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Or visit their website at: http://www.gnu.org/

Definition in file random.c.


Function Documentation

void RandInit (  ) 

Initalizes the random number generator, or opens access to an existing one.

On non-Windows systems, this will attempt to open /dev/urandom. If it cannot be opened or if the program is compiled on Windows, it will fallback on the ANSI C pseudo random number generator.

Definition at line 36 of file random.c.

References urand.

Referenced by ioThread(), and main().

Uint32 RandNum (  ) 

Obtains a random number.

If the ANSI C pseudo random number generator is being used, it will be called twice and place the first result in the upper 16-bits, and the second result in the lower 16-bits. This will normally result in 30-bits of random data. If /dev/urandom is being used, 4 bytes will be read and placed in the integer for 32-bits of randomness.

Definition at line 48 of file random.c.

References urand.

Referenced by DiscoverConnectServer(), and SpawnTank().

void RandUninit (  ) 

Uninitalizes the random number generator.

If /dev/urandom is in use, the file will be closed.

Definition at line 62 of file random.c.

References urand.

Referenced by main().


Variable Documentation

FILE* urand = NULL [static]

A file handle used to access a random number device run by the operating system.

Definition at line 33 of file random.c.

Referenced by RandInit(), RandNum(), and RandUninit().


Generated on Mon May 28 04:41:40 2007 for Retro Tank Super Attack by  doxygen 1.5.2