server/src/util/rng.h
Enno Rehling 03c247c788 I am killing the core/ directory.
Lots of files are moving to a new location in src/
Some intersting CMake changes.
2014-02-18 05:45:00 +01:00

45 lines
1.2 KiB
C

/* vi: set ts=2:
* +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
* | | Enno Rehling <enno@eressea.de>
* | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
* | (c) 1998 - 2005 |
* | | This program may not be used, modified or distributed
* +-------------------+ without prior permission by the authors of Eressea.
*
*/
#ifndef UTIL_RNG_H
#define UTIL_RNG_H
#ifdef __cplusplus
extern "C" {
#endif
#define RNG_MT
#ifdef RNG_MT
/* initializes mt[N] with a seed */
extern void init_genrand(unsigned long s);
/* generates a random number on [0,0xffffffff]-interval */
extern unsigned long genrand_int32(void);
/* generates a random number on [0,1)-real-interval */
extern double genrand_real2(void);
/* generates a random number on [0,0x7fffffff]-interval */
long genrand_int31(void);
# define rng_init(seed) init_genrand(seed)
# define rng_int genrand_int31
# define rng_double genrand_real2
# define RNG_RAND_MAX 0x7fffffff
#else
# include <stdlib.h>
# define rng_init(seed) srand(seed)
# define rng_int rand()
# define rng_double ((rand()%RAND_MAX)/(double)RAND_MAX)
# define RNG_RAND_MAX RAND_MAX
#endif
#ifdef __cplusplus
}
#endif
#endif