pseudo random distribution which guarantees all possible permutations of value sequence - C++

前端 未结 3 1922
天命终不由人
天命终不由人 2021-01-13 16:53

Random question.

I am attempting to create a program which would generate a pseudo-random distribution. I am trying to find the right pseudo-random algorithm for my

3条回答
  •  迷失自我
    2021-01-13 17:42

    Ok, I'm not sure if there is a general answer, so I would concentrate on random number generator having, say, 64bit internal state/seed, producing 64bit output and having 2^64-1 period. In particular, I would look at linear congruential generator (aka LCG) in the form of

    next = (a * prev + c) mod m
    

    where a and m are primes to each other

    So:

    1) Check

    2) Check

    3) Check (well, for 64bit space of course)

    4) Check (again, except 0 I believe, but each and every permutation of 64bits is output of LCG starting with some seed)

    5) Check. LCG is known to be reversible, i.e. one could get

    prev = (next - c) * a_inv mod m
    

    where a_inv could be computed from a, m using Euclid's algorithm

    Well, if it looks ok to you, you could try to implement LCG in your 15546bits space

    UPDATE

    And quick search shows reversible LCG discussion/code here

    Reversible pseudo-random sequence generator

提交回复
热议问题