Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

jrnd.h

Go to the documentation of this file.
00001 /*
00002 ** Jason Winnebeck, v2.1  3/8/00
00003 ** Also merged with jrnd2.h, a somewhat private implementation of
00004 ** jrnd which used fixed numbers, designed for the Allegro library
00005 ** This file is public domain
00006 **
00007 ** Version 2.1 added #undefs in rndalgor.c to prevent conflicts.
00008 **
00009 ** Remember to add jrndglob.h to one of your .c/cpp files, or add
00010 ** rndalgor.c to your project and only include this.
00011 */
00012 
00013 #ifndef _JRND_H_
00014 #define _JRND_H_
00015 
00016 #ifdef __cplusplus
00017 
00018 #include <time.h>
00019 
00020 /* prototypes for the RNG */
00021 long longrand(void);                    /* return next random long */
00022 void slongrand(unsigned long seed);     /* to seed it */
00023 
00024 #define MAX_LONG 0x7FFFFFFF
00025 
00026 /* 
00027 ** Initialize the generator
00028 */
00029 inline void randomize() {
00030   slongrand((unsigned) time(NULL));
00031 }
00032 
00033 /* 
00034 ** Initialize the generator
00035 ** analogous to Borland C++'s randomize() function
00036 */
00037 inline void randomize(long seed) {
00038   slongrand(seed);
00039 }
00040 
00041 /*
00042 ** returns between 0 and (high - 1) INCLUSIVE
00043 ** analogous to Borland C++'s random(int x) function
00044 */
00045 inline long getrnd(long high) {
00046   if (high == 0L)
00047     return 0L;
00048   else
00049     return longrand() % high;
00050 }
00051 
00052 /*
00053 ** returns between low and high INCLUSIVE
00054 */
00055 inline long getrnd(long high, long low) {
00056   if ((high - low) == -1L)
00057     return high;
00058   else
00059     return longrand() % (high - low + 1L) + low;
00060 }
00061 
00062 /*
00063 ** returns a decimal between 0 EXCLUSIVE and high INCLUSIVE
00064 */
00065 inline float getrndf(float high) {
00066   return float(longrand()) / (float)MAX_LONG * high;
00067 }
00068 
00069 /*
00070 ** returns a decimal between low INCLUSIVE and high INCLUSIVE
00071 */
00072 inline float getrndf(float high, float low) {
00073   return float(longrand()) / (float)MAX_LONG * (high - low) + low;
00074 }
00075 
00076 #else  /* #ifdef __cplusplus */
00077 #include "jrndc.h" /*instead*/
00078 #endif /* #ifdef __cplusplus */
00079 
00080 #endif /* #ifndef _JRND_H_ */

Generated on Tue Mar 4 02:29:25 2003 for SuperIsoBomb by doxygen1.2.18