Skip to content

rnd.next(long long n) produces a periodic sequence when n is a power of 2 #165

@Weierstras-s

Description

@Weierstras-s

It seems that the period is $32768\cdot n$ when $n=2^k$.

The output of the following code is 1.

#include <bits/stdc++.h>
using namespace std;

int main(int argc, char *argv[]){
    registerGen(argc, argv, 1);

    const long long n = 2;
    
    string s, t;
    for (int i = 0; i < 32768 * n; ++i)
        s += rnd.next(n) + '0';
    for (int i = 0; i < 32768 * n; ++i)
        t += rnd.next(n) + '0';
    cout << (s == t);
    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions