Added random functions which work on a supplied RNG state.

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2714 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
Meep-Eep
2007-04-01 21:13:41 +00:00
parent f69b7bddec
commit c6394ab882
3 changed files with 25 additions and 2 deletions
+1 -1
View File
@@ -1 +1 @@
uqm_CFILES="random.c sqrt.c" uqm_CFILES="random.c random2.c sqrt.c"
+2 -1
View File
@@ -61,7 +61,8 @@ static DWORD seed = 12345L; /* random number seed */
DWORD DWORD
TFB_Random (void) TFB_Random (void)
{ {
if ((seed = A * (seed % Q) - R * (seed / Q)) > M) seed = A * (seed % Q) - R * (seed / Q);
if (seed > M)
return (seed -= M); return (seed -= M);
else if (seed) else if (seed)
return (seed); return (seed);
+22
View File
@@ -26,6 +26,9 @@
* Copyright (c) 1989, Robert Leyland and Scott Anderson * Copyright (c) 1989, Robert Leyland and Scott Anderson
****************************************************************************/ ****************************************************************************/
#ifndef _RANDOM_H
#define _RANDOM_H
/* ----------------------------DEFINES------------------------------------ */ /* ----------------------------DEFINES------------------------------------ */
#define RAND(n) ( (int) ( (unsigned int)TFB_Random() % (n) ) ) #define RAND(n) ( (int) ( (unsigned int)TFB_Random() % (n) ) )
@@ -38,3 +41,22 @@
DWORD TFB_SeedRandom (DWORD seed); DWORD TFB_SeedRandom (DWORD seed);
DWORD TFB_Random (void); DWORD TFB_Random (void);
typedef struct RandomContext RandomContext;
#ifdef RANDOM2_INTERNAL
struct RandomContext {
DWORD seed;
};
#endif
RandomContext *RandomContext_New (void);
void RandomContext_Delete (RandomContext *context);
RandomContext *RandomContext_Copy (const RandomContext *source);
DWORD RandomContext_Random (RandomContext *context);
DWORD RandomContext_SeedRandom (RandomContext *context, DWORD new_seed);
#endif /* _RANDOM_H */