What are the better (pseudo) random number generator than the LCG for lottery scheduler?

后端 未结 3 1071
滥情空心
滥情空心 2020-12-30 17:15

I want to design a lottery scheduler and I need to have a very good (pseudo) random number generator similar to LCG but I was wondering if there are other better choice out

3条回答
  •  礼貌的吻别
    2020-12-30 17:51

    If you need simple but decent quality, I would use the upper 32 (or fewer) bits of a 64-bit LCG, possibly with a tempering function applied to the output. When doing this, I've copied the tempering function used in Mersenne Twister. I would not recommend actually using Mersenne Twister, as it has a lot more complexity and internal state than other PRNGs without significantly better qualities.

    Here is some sample code:

    static uint32_t temper(uint32_t x)
    {
        x ^= x>>11;
        x ^= x<<7 & 0x9D2C5680;
        x ^= x<<15 & 0xEFC60000;
        x ^= x>>18;
        return x;
    }
    uint32_t lcg64_temper(uint64_t *seed)
    {
        *seed = 6364136223846793005ULL * *seed + 1;
        return temper(*seed >> 32);
    }
    

提交回复
热议问题