Renamed randnormal to randomnormal

--HG--
branch : math-randobject
This commit is contained in:
Alex Szpakowski
2013-04-15 14:57:20 -03:00
parent 3046981fce
commit d98e2cb40c
8 changed files with 21 additions and 21 deletions
@@ -140,8 +140,8 @@ void ParticleSystem::add()
pLast->position[1] += Math::instance.random(-areaSpread.getY(), areaSpread.getY());
break;
case DISTRIBUTION_NORMAL:
pLast->position[0] += Math::instance.randnormal(areaSpread.getX());
pLast->position[1] += Math::instance.randnormal(areaSpread.getY());
pLast->position[0] += Math::instance.randomnormal(areaSpread.getX());
pLast->position[1] += Math::instance.randomnormal(areaSpread.getY());
break;
case DISTRIBUTION_NONE:
default:
+3 -3
View File
@@ -80,11 +80,11 @@ public:
}
/**
* @copydoc RandomGenerator::randnormal()
* @copydoc RandomGenerator::randomnormal()
**/
inline double randnormal(double stddev)
inline double randomnormal(double stddev)
{
return rng->randnormal(stddev);
return rng->randomnormal(stddev);
}
/**
+6 -6
View File
@@ -32,7 +32,7 @@ namespace math
// George Marsaglia, "Xorshift RNGs", Journal of Statistical Software, Vol.8 (Issue 14), 2003
RandomGenerator::RandomGenerator()
: last_randnormal(std::numeric_limits<double>::infinity())
: last_randomnormal(std::numeric_limits<double>::infinity())
{
// because it is too big for some compilers to handle ... if you know what
// i mean
@@ -66,20 +66,20 @@ uint64 RandomGenerator::rand()
}
// BoxMuller transform
double RandomGenerator::randnormal(double stddev)
double RandomGenerator::randomnormal(double stddev)
{
// use cached number if possible
if (last_randnormal != std::numeric_limits<double>::infinity())
if (last_randomnormal != std::numeric_limits<double>::infinity())
{
double r = last_randnormal;
last_randnormal = std::numeric_limits<double>::infinity();
double r = last_randomnormal;
last_randomnormal = std::numeric_limits<double>::infinity();
return r * stddev;
}
double r = sqrt(-2.0 * log(1. - random()));
double phi = 2.0 * LOVE_M_PI * (1. - random());
last_randnormal = r * cos(phi);
last_randomnormal = r * cos(phi);
return r * sin(phi) * stddev;
}
+2 -2
View File
@@ -96,12 +96,12 @@ public:
* @param stddev Standard deviation of the distribution.
* @return Normally distributed random number with mean 0 and variance (stddev)².
**/
double randnormal(double stddev);
double randomnormal(double stddev);
private:
uint64 rng_state;
double last_randnormal;
double last_randomnormal;
}; // RandomGenerator
+3 -3
View File
@@ -42,7 +42,7 @@ int w_random(lua_State *L)
return luax_getrandom(L, 1, Math::instance.random());
}
int w_randnormal(lua_State *L)
int w_randomnormal(lua_State *L)
{
double mean = 0.0, stddev = 1.0;
if (lua_gettop(L) > 1)
@@ -55,7 +55,7 @@ int w_randnormal(lua_State *L)
stddev = luaL_optnumber(L, 1, 1.);
}
double r = Math::instance.randnormal(stddev);
double r = Math::instance.randomnormal(stddev);
lua_pushnumber(L, r + mean);
return 1;
}
@@ -153,7 +153,7 @@ static const luaL_Reg functions[] =
{
{ "randomseed", w_randomseed },
{ "random", w_random },
{ "randnormal", w_randnormal },
{ "randomnormal", w_randomnormal },
{ "newRandomGenerator", w_newRandomGenerator },
{ "triangulate", w_triangulate },
{ 0, 0 }
+1 -1
View File
@@ -32,7 +32,7 @@ namespace math
int w_randomseed(lua_State *L);
int w_random(lua_State *L);
int w_randnormal(lua_State *L);
int w_randomnormal(lua_State *L);
int w_newRandomGenerator(lua_State *L);
int w_triangulate(lua_State *L);
extern "C" LOVE_EXPORT int luaopen_love_math(lua_State *L);
+3 -3
View File
@@ -85,7 +85,7 @@ int w_RandomGenerator_random(lua_State *L)
return luax_getrandom(L, 2, rng->random());
}
int w_RandomGenerator_randnormal(lua_State *L)
int w_RandomGenerator_randomnormal(lua_State *L)
{
RandomGenerator *rng = luax_checkrandomgenerator(L, 1);
@@ -100,7 +100,7 @@ int w_RandomGenerator_randnormal(lua_State *L)
stddev = luaL_optnumber(L, 2, 1.0);
}
double r = rng->randnormal(stddev);
double r = rng->randomnormal(stddev);
lua_pushnumber(L, r + mean);
return 1;
}
@@ -109,7 +109,7 @@ static const luaL_Reg functions[] =
{
{ "randomseed", w_RandomGenerator_randomseed },
{ "random", w_RandomGenerator_random },
{ "randnormal", w_RandomGenerator_randnormal },
{ "randomnormal", w_RandomGenerator_randomnormal },
{ 0, 0 }
};
+1 -1
View File
@@ -38,7 +38,7 @@ int luax_getrandom(lua_State *L, int startidx, double r);
RandomGenerator *luax_checkrandomgenerator(lua_State *L, int idx);
int w_RandomGenerator_randomseed(lua_State *L);
int w_RandomGenerator_random(lua_State *L);
int w_RandomGenerator_randnormal(lua_State *L);
int w_RandomGenerator_randomnormal(lua_State *L);
extern "C" int luaopen_randomgenerator(lua_State *L);
} // math