I can use one of two methods to create a pseudo random number sequence that has two important characteristics - (1) it is reproducible on different machines, and (2) the sequence never repeats a number within range until all have been emitted.
My question is - do either of these methods have potential issues with regards to portability (OS, Python versions, etc)? For example, does anyone know if I would get one set of results on one system but a different one on another when XXX is true?
I'm not really asking for advice on which method to use per se, only if I should watch out for X on Y system when Z is true.
I have tried on a few versions of Linux, all 64bit, and they seem consistent, but I don't have easy access to Windows or 32 bit versions.
Note that they don't produce the same ranges as each other, but that's OK for my purposes. The numbers just have to appear random to the human eye.
Method 1
generates a random sample from a range using native Python library functions. It's slow if I use large ranges (10m or more) but OK for relatively small ones, and is much easier to understand for people without a degree in maths :
import random
random.seed(5)
x = random.sample(range(10000,99999),89999)
for i in range(10):
print(x[i])
Method 2
uses an algorithm not from a Python library :
(https://en.wikipedia.org/wiki/Linear_congruential_generator)
It's super fast even for massive ranges, but harder to understand and therefore spot potential issues with :
def lcg(modulus, a, c, seed):
while True:
seed = (a * seed + c) % modulus
yield seed
m = 10000019
c = int(m/2)
a = 5653
s = a
g = lcg(m,a,c,s)
for _ in range(10):
print(next(g))
Note I am more than open to alternatives; the original question was asked here : https://math.stackexchange.com/questions/3289084/generate-a-pseudo-random-predictable-non-repeating-integer-sequence-purely-math