commit x64 compilation from lulu cause the other branch dont seems to compile properly at home
This commit is contained in:
69
include/platform/rand/rand.cpp
Normal file
69
include/platform/rand/rand.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "rand/rand.h"
|
||||
|
||||
using namespace GS;
|
||||
|
||||
|
||||
#define __USE_CUSTOM_RAND 1
|
||||
|
||||
static uint high = 0xDEADBEEF, low = high ^ 0x49616E42;
|
||||
static uint _rg_pn = 0;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void Random::Seed(uint s)
|
||||
{
|
||||
#if __USE_CUSTOM_RAND
|
||||
high = 0xDEADBEEF;
|
||||
low = high ^ 0x49616E42;
|
||||
for (uint n = 0; n < (s & 0x1fff); ++n)
|
||||
Rand(1);
|
||||
#else
|
||||
srand(s);
|
||||
#endif
|
||||
}
|
||||
uint Random::Rand(uint r)
|
||||
{
|
||||
if (!r)
|
||||
return 0;
|
||||
#if __USE_CUSTOM_RAND
|
||||
high = (high << 16) + (high >> 16);
|
||||
high += low;
|
||||
low += high;
|
||||
return high % r;
|
||||
#else
|
||||
return rand() % r;
|
||||
#endif
|
||||
}
|
||||
float Random::FRand(float r)
|
||||
{
|
||||
return (float)Rand(65536) * r / 65536.0f;;
|
||||
}
|
||||
float Random::FRRand(float lo, float hi)
|
||||
{
|
||||
const float v = (float)(Rand(65536)) / 65536.0f;
|
||||
return v * (hi - lo) + lo;
|
||||
}
|
||||
uint Random::CRand(uint r)
|
||||
{
|
||||
uint it;
|
||||
uint _rg_cn = 0;
|
||||
|
||||
if (!r)
|
||||
return 0;
|
||||
|
||||
it = 4;
|
||||
while (it--)
|
||||
{
|
||||
_rg_cn = Rand(r);
|
||||
if (_rg_cn != _rg_pn)
|
||||
break;
|
||||
}
|
||||
_rg_pn = _rg_cn;
|
||||
return _rg_cn;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user