mirror of
https://github.com/love2d/love.git
synced 2026-08-13 17:10:54 +02:00
Changed love.math.randomnormal([mean], stddev) to love.math.randomNormal(stddev, [mean]);
Changed love.math.randomseed(seed) to love.math.setRandomState(state) and love.math.setRandomState(low, high). Added low, high = love.math.getRandomState(). love.math.setRandomState(state) can set the random state to an integer of up to 53 bits, love.math.setRandomState(low, high) can set the random state to a 64 bit integer by using the first argument as the lower 32 bits and the second argument as the higher 32 bits. This allows for reliable setting and saving of the state of a RNG. --HG-- branch : RandomGenerator-2
This commit is contained in:
@@ -36,37 +36,25 @@ RandomGenerator::RandomGenerator()
|
||||
{
|
||||
// because it is too big for some compilers to handle ... if you know what
|
||||
// i mean
|
||||
union
|
||||
{
|
||||
uint64 b64;
|
||||
struct
|
||||
{
|
||||
uint32 a;
|
||||
uint32 b;
|
||||
} b32;
|
||||
} converter;
|
||||
|
||||
#ifdef LOVE_BIG_ENDIAN
|
||||
converter.b32.a = 0x0139408D;
|
||||
converter.b32.b = 0xCBBF7A44;
|
||||
rng_state.b32.a = 0x0139408D;
|
||||
rng_state.b32.b = 0xCBBF7A44;
|
||||
#else
|
||||
converter.b32.b = 0x0139408D;
|
||||
converter.b32.a = 0xCBBF7A44;
|
||||
rng_state.b32.b = 0x0139408D;
|
||||
rng_state.b32.a = 0xCBBF7A44;
|
||||
#endif
|
||||
|
||||
rng_state = converter.b64;
|
||||
}
|
||||
|
||||
uint64 RandomGenerator::rand()
|
||||
{
|
||||
rng_state ^= (rng_state << 13);
|
||||
rng_state ^= (rng_state >> 7);
|
||||
rng_state ^= (rng_state << 17);
|
||||
return rng_state;
|
||||
rng_state.b64 ^= (rng_state.b64 << 13);
|
||||
rng_state.b64 ^= (rng_state.b64 >> 7);
|
||||
rng_state.b64 ^= (rng_state.b64 << 17);
|
||||
return rng_state.b64;
|
||||
}
|
||||
|
||||
// Box–Muller transform
|
||||
double RandomGenerator::randomnormal(double stddev)
|
||||
double RandomGenerator::randomNormal(double stddev)
|
||||
{
|
||||
// use cached number if possible
|
||||
if (last_randomnormal != std::numeric_limits<double>::infinity())
|
||||
|
||||
Reference in New Issue
Block a user