aboutsummaryrefslogtreecommitdiffstats
path: root/code/qcommon
diff options
context:
space:
mode:
authorthilo <thilo@edf5b092-35ff-0310-97b2-ce42778d08ea>2009-05-31 19:48:28 +0000
committerthilo <thilo@edf5b092-35ff-0310-97b2-ce42778d08ea>2009-05-31 19:48:28 +0000
commite3fc31a512c6636777ab81a31eff789f2d4c64ff (patch)
treed13f686d79db091c7bbf5c5cc8a706a3d92ec70c /code/qcommon
parent25f4f42f9bfa511cc7e170a379855f5c2419a8d2 (diff)
downloadioquake3-aero-e3fc31a512c6636777ab81a31eff789f2d4c64ff.tar.gz
ioquake3-aero-e3fc31a512c6636777ab81a31eff789f2d4c64ff.zip
- Introduce seeding of the random number generator at startup
- Replaced all engine-side occurances of rand() with random() git-svn-id: svn://svn.icculus.org/quake3/trunk@1561 edf5b092-35ff-0310-97b2-ce42778d08ea
Diffstat (limited to 'code/qcommon')
-rw-r--r--code/qcommon/common.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/code/qcommon/common.c b/code/qcommon/common.c
index e8a95a5..0f28072 100644
--- a/code/qcommon/common.c
+++ b/code/qcommon/common.c
@@ -2502,6 +2502,22 @@ static void Com_DetectAltivec(void)
/*
=================
+Com_InitRand
+Seed the random number generator, if possible with an OS supplied random seed.
+=================
+*/
+static void Com_InitRand(void)
+{
+ unsigned int seed;
+
+ if(Sys_Random(&seed, sizeof(seed)))
+ srand(seed);
+ else
+ srand(time(NULL));
+}
+
+/*
+=================
Com_Init
=================
*/
@@ -2519,8 +2535,11 @@ void Com_Init( char *commandLine ) {
Com_Memset( &eventQueue[ 0 ], 0, MAX_QUEUED_EVENTS * sizeof( sysEvent_t ) );
Com_Memset( &sys_packetReceived[ 0 ], 0, MAX_MSGLEN * sizeof( byte ) );
- // do this before anything else decides to push events
- Com_InitPushEvent();
+ // initialize the weak pseudo-random number generator for use later.
+ Com_InitRand();
+
+ // do this before anything else decides to push events
+ Com_InitPushEvent();
Com_InitSmallZoneMemory();
Cvar_Init ();
@@ -3322,8 +3341,7 @@ void Com_RandomBytes( byte *string, int len )
return;
Com_Printf( "Com_RandomBytes: using weak randomization\n" );
- srand( time( 0 ) );
for( i = 0; i < len; i++ )
- string[i] = (unsigned char)( rand() % 255 );
+ string[i] = (unsigned char)( random() % 255 );
}