Hi,
I am using a LehmerRandom generator to create procedural content. Originally it worked using two coordinates basically X and Y. I am looking to make it use at minimum x,y,z,g. The last code is a function to return a unsigned 64 integer but my understanding it’s not BP usable so I probably have to make it signed integer and then the c++ function that uses the seed from signed to unsigned. It’s based on The fastest conventional random number generator that can pass Big Crush? – Daniel Lemire's blog and a modification of the latter code.
I am just wondering would this work with Unreal c++. The part that throws me off is the.
`seed = (x&0xFFFFFFFF)<<48|(y&0xFFFFFFFF)<<32|(z&0xFFFFFF)<<16|(s&0xFFFFFF);`
Modified Code
#pragma once
class LehmerRandom2
{
public:
__uint128_t nProcGen = 0;
double rndDouble(double min, double max)
{
return ((double)rnd() / (double)(0x7FFFFFFF)) * (max - min) + min;
};
int rndInt(int min, int max)
{
return (rnd() % (max - min)) + min;
};
uint64_t rnd()
{
nProcGen *=0xda942042e4dd58b5;
return nProcGen << 64;
};
};
////////////////
uint64_t UProcGalaxy::bpCoordinate4DTest(int64 x, int64 y, int64 z, int64 s)
{
uint64_t seed = 0;
seed = (x&0xFFFFFFFF)<<48|(y&0xFFFFFFFF)<<32|(z&0xFFFFFF)<<16|(s&0xFFFFFF);
return (uint64_t) seed;
}
Original Code
#pragma once
class LehmerRandom
{
public:
uint32_t nProcGen = 0;
double rndDouble(double min, double max)
{
return ((double)rnd() / (double)(0x7FFFFFFF)) * (max - min) + min;
};
int rndInt(int min, int max)
{
return (rnd() % (max - min)) + min;
};
// Modified from this for 64-bit systems:
// https://lemire.me/blog/2019/03/19/the-fastest-conventional-random-number-generator-that-can-pass-big-crush/
// Now I found the link again - Also, check out his blog, it's a fantastic resource!
uint32_t rnd()
{
nProcGen += 0xe120fc15;
uint64_t tmp;
tmp = (uint64_t)nProcGen * 0x4a39b70d;
uint32_t m1 = (tmp >> 32) ^ tmp;
tmp = (uint64_t)m1 * 0x12fad5c9;
uint32_t m2 = (tmp >> 32) ^ tmp;
return m2;
};
};