a pseudorandom number generator the default value for seed is the result of a function call which is not normally recommended and causes ruff to raise a b008 error however in this case it is acceptable because linearcongruentialgenerator init will only be called once per instance and it ensures that each instance will generate a unique sequence of numbers these parameters are saved and used when nextnumber is called modulo is the largest number that can be generated exclusive the most efficient values are powers of 2 232 is a common value the smallest number that can be generated is zero the largest number that can be generated is modulo1 modulo is set in the constructor show the lcg in action a pseudorandom number generator the default value for seed is the result of a function call which is not normally recommended and causes ruff to raise a b008 error however in this case it is acceptable because linearcongruentialgenerator __init__ will only be called once per instance and it ensures that each instance will generate a unique sequence of numbers noqa b008 these parameters are saved and used when nextnumber is called modulo is the largest number that can be generated exclusive the most efficient values are powers of 2 2 32 is a common value the smallest number that can be generated is zero the largest number that can be generated is modulo 1 modulo is set in the constructor show the lcg in action
__author__ = "Tobias Carryer"

from time import time


class LinearCongruentialGenerator:
    

    
    
    
    
    

    def __init__(self, multiplier, increment, modulo, seed=int(time())):  
        
        self.multiplier = multiplier
        self.increment = increment
        self.modulo = modulo
        self.seed = seed

    def next_number(self):
        
        self.seed = (self.multiplier * self.seed + self.increment) % self.modulo
        return self.seed


if __name__ == "__main__":
    
    lcg = LinearCongruentialGenerator(1664525, 1013904223, 2 << 31)
    while True:
        print(lcg.next_number())