Implement crandk() and frandk() and remove old functions

This commit is contained in:
Yamagi Burmeister 2012-06-02 11:13:25 +02:00
parent 7bd1392a5a
commit effc7b3c35
3 changed files with 28 additions and 16 deletions

View file

@ -699,9 +699,6 @@ void Com_SetServerState (int state);
unsigned Com_BlockChecksum (void *buffer, int length);
byte COM_BlockSequenceCRCByte (byte *base, int length, int sequence);
float frand(void); /* 0 ti 1 */
float crand(void); /* -1 to 1 */
extern cvar_t *developer;
extern cvar_t *modder;
extern cvar_t *dedicated;
@ -759,6 +756,8 @@ void SV_Frame (int msec);
/* Random number generator */
int randk(void);
float frandk(void);
float crandk(void);
void randk_seed(void);
#endif

View file

@ -157,16 +157,6 @@ byte COM_BlockSequenceCRCByte (byte *base, int length, int sequence)
return r;
}
float frand(void)
{
return (rand()&32767)* (1.0/32767);
}
float crand(void)
{
return (rand()&32767)* (2.0/32767) - 1;
}
#ifndef DEDICATED_ONLY
void Key_Init (void);
void SCR_EndLoadingPlaque (void);

View file

@ -25,7 +25,7 @@ static int j;
static uint64_t carry;
static uint64_t xs;
static uint64_t cng;
uint64_t
B64MWC(void)
{
@ -36,7 +36,7 @@ B64MWC(void)
t = (x << 28) + carry;
carry = (x >> 36) - (t < x);
return QARY[j] = t - x;
}
}
/*
* Generate a pseudorandom
@ -47,7 +47,30 @@ randk(void)
{
return (int)KISS;
}
/*
* Generate a pseudorandom
* signed float between
* 0 and 1.
*/
float
frandk(void)
{
return (randk()&32767)* (1.0/32767);
}
/* Generate a pseudorandom
* float between -1 and 1.
*/
float
crandk(void)
{
return (randk()&32767)* (2.0/32767) - 1;
}
/*
* Seeds the PRNG
*/
void
randk_seed(void)
{