00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _JRND_H_
00014 #define _JRND_H_
00015
00016 #ifdef __cplusplus
00017
00018 #include <time.h>
00019
00020
00021 long longrand(void);
00022 void slongrand(unsigned long seed);
00023
00024 #define MAX_LONG 0x7FFFFFFF
00025
00026
00027
00028
00029 inline void randomize() {
00030 slongrand((unsigned) time(NULL));
00031 }
00032
00033
00034
00035
00036
00037 inline void randomize(long seed) {
00038 slongrand(seed);
00039 }
00040
00041
00042
00043
00044
00045 inline long getrnd(long high) {
00046 if (high == 0L)
00047 return 0L;
00048 else
00049 return longrand() % high;
00050 }
00051
00052
00053
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
00064
00065 inline float getrndf(float high) {
00066 return float(longrand()) / (float)MAX_LONG * high;
00067 }
00068
00069
00070
00071
00072 inline float getrndf(float high, float low) {
00073 return float(longrand()) / (float)MAX_LONG * (high - low) + low;
00074 }
00075
00076 #else
00077 #include "jrndc.h"
00078 #endif
00079
00080 #endif