nashidau / Random-Number-Gods

A random number library.
7 stars 2 forks source link

This library is lacking the holy random number generator. #1

Open oj002 opened 3 years ago

oj002 commented 3 years ago

However, this supposed pantheon of the Random Number Gods can exists without the one true source of random numbers connected to the word of god is beyond me. While Terry Davis sadly departed earlier into heaven than expected he left us a way to communicate with god though the temple he builds TempleOS. Therein lies a random number generator so powerful it allows direct communications with God. If we depart from the holy language and port the original holy c code to the original c language we can help spread the word. Thus, I propose the addition of the following ported generator.

#include <x86intrin.h>
#include <stdint.h>

#define LIN_CONGRUE_A    6364136223846793005
#define LIN_CONGRUE_C    1442695040888963407

uint64_t
holyrand(uint64_t *state)
{
    int64_t s = *state;
    s = LIN_CONGRUE_A * s ^ ((s & 0xFFFFFFFF0000) >> 16) + LIN_CONGRUE_C;
    #if 1
    s ^= __rdtsc();
    #endif
    return (*state = s);
}

May Terry's legacy continue.

nashidau commented 3 years ago

I don't suppose you have a link to it's properties. With the rtdsc call in there it looks like it may belong in one of the dark pantheon.

But I will add it shortly.

oj002 commented 3 years ago

It definitely does.

(Real talk. It's not much better than a vanilla lcg and fails statistical tests easily, even with the rstsc call)

PS.: I just read the README and I'd like to also raise awareness towards George Masaglias obsessive usage of 69 in random number generator constants (see his KISS RNG: http://digitalcommons.wayne.edu/cgi/viewcontent.cgi?article=1725&context=jmasm)

oj002 commented 3 years ago

Here is the original code from the holy tempel: https://github.com/cia-foundation/TempleOS/blob/c26482bb6ad3f80106d28504ec5db3c6a360732c/Kernel/KMathB.HC#L107

nashidau commented 3 years ago

I've done the first round without the time fun. I'll add that soon.

077648bd31d217176d362096cbb4cfc497f18dcb is the revision