相关疑难解决方法(0)

PRNG,周期可调

我需要构建一个可调周期的就地伪随机数生成器。此外,一个时期内不得有任何碰撞。也就是说,以下必须返回true:

// prng is "generated" at run-time
// (though a by-hand solution would work)

bool test(func prng, int period) {
    int seed = 0;  // Any number should work
    int cur = seed;

    for (int i = 0; i <= period; ++i) {
        cur = prng(cur);

        if (cur == seed) {
            if (i == period) {
                // We hit our period on target
                return true;
            }

            // Period too low (we hit our seed already!)
            return false;
        }
    }

    // …
Run Code Online (Sandbox Code Playgroud)

language-agnostic random

5
推荐指数
1
解决办法
652
查看次数

标签 统计

language-agnostic ×1

random ×1