X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=mathlib.h;h=0acb9500627fc2e3aa20f3c20f83c304e05273d3;hb=dfc53802fb3f67b604e61a92fc6a268651b38b04;hp=cb674e51a38affd019b3f023ad9e038f824da038;hpb=98a14be269dba68ac9a23c23d094687e83dbdb40;p=xonotic%2Fdarkplaces.git diff --git a/mathlib.h b/mathlib.h index cb674e51..0acb9500 100644 --- a/mathlib.h +++ b/mathlib.h @@ -181,9 +181,10 @@ int PointInfrontOfTriangle(const float *p, const float *a, const float *b, const } #endif -#define lhcheeserand() (seed = (seed * 987211u) ^ (seed >> 13u) ^ 914867) -#define lhcheeserandom(MIN,MAX) ((double)(lhcheeserand() + 0.5) / ((double)4096.0*1024.0*1024.0) * ((MAX)-(MIN)) + (MIN)) -#define VectorCheeseRandom(v) do{(v)[0] = lhcheeserandom(-1, 1);(v)[1] = lhcheeserandom(-1, 1);(v)[2] = lhcheeserandom(-1, 1);}while(DotProduct(v, v) > 1) +#define lhcheeserand(seed) ((seed) = ((seed) * 987211u) ^ ((seed) >> 13u) ^ 914867) +#define lhcheeserandom(seed,MIN,MAX) ((double)(lhcheeserand(seed) + 0.5) / ((double)4096.0*1024.0*1024.0) * ((MAX)-(MIN)) + (MIN)) +#define VectorCheeseRandom(seed,v) do{(v)[0] = lhcheeserandom(seed,-1, 1);(v)[1] = lhcheeserandom(seed,-1, 1);(v)[2] = lhcheeserandom(seed,-1, 1);}while(DotProduct(v, v) > 1) +#define VectorLehmerRandom(seed,v) do{(v)[0] = Math_crandomf(seed);(v)[1] = Math_crandomf(seed);(v)[2] = Math_crandomf(seed);}while(DotProduct(v, v) > 1) /* // LordHavoc: quaternion math, untested, don't know if these are correct, @@ -301,6 +302,22 @@ void BoxFromPoints(vec3_t mins, vec3_t maxs, int numpoints, vec_t *point3f); int LoopingFrameNumberFromDouble(double t, int loopframes); +// implementation of 128bit Lehmer Random Number Generator with 2^126 period +// https://en.wikipedia.org/Lehmer_random_number_generator +typedef struct randomseed_s +{ + unsigned int s[4]; +} +randomseed_t; + +void Math_RandomSeed_Reset(randomseed_t *r); +void Math_RandomSeed_FromInts(randomseed_t *r, unsigned int s0, unsigned int s1, unsigned int s2, unsigned int s3); +unsigned long long Math_rand64(randomseed_t *r); +float Math_randomf(randomseed_t *r); +float Math_crandomf(randomseed_t *r); +float Math_randomrangef(randomseed_t *r, float minf, float maxf); +int Math_randomrangei(randomseed_t *r, int mini, int maxi); + void Mathlib_Init(void); #endif