lemur icon indicating copy to clipboard operation
lemur copied to clipboard

Random library

Open Kampfkarren opened this issue 6 years ago • 6 comments

I was going to implement this, but I don't know of a good PRNG that doesn't need bitmath, and I'm not entirely comfortable making a bit library a dependency.

Kampfkarren avatar Aug 15 '18 02:08 Kampfkarren

Since relying on randomness in a test is probably not a great idea, we could always make it return a constant value as a shim, or expose the API but make everything throw an error.

LPGhatguy avatar Aug 15 '18 17:08 LPGhatguy

I don't like making everything error, I have some code I'd like to test that uses Random in their initialization but are otherwise consistent and testable. I propose just picking the middle of the two values provided (defaulting to 0 and 1 for NextNumber).

Kampfkarren avatar Aug 16 '18 03:08 Kampfkarren

Because you can have a predictable seed in Roblox for Random (and you can rely on that sequence), it'd probably be inappropriate for Lemur to implement a different strategy, now that I think about it more.

LPGhatguy avatar Aug 16 '18 18:08 LPGhatguy

So what are you suggesting? Mirroring XSH-RR PCG with the exact same constants as Roblox?

Kampfkarren avatar Aug 16 '18 20:08 Kampfkarren

I think supporting this in Lemur would probably involve writing a LuaRocks rock that implements the same RNG as Roblox (right, PCG) in C/C++ and then adding it as an optional dependency for Lemur.

LPGhatguy avatar Aug 17 '18 17:08 LPGhatguy

The algorithm Roblox uses has magic constants, so that's something you or another engineer would have to acquire (I'm not interested in breaking the ToS and reverse engineering the exe, much less complicated bitmath 😋)

Kampfkarren avatar Aug 17 '18 18:08 Kampfkarren