jeudi 17 septembre 2020

Linear congruential generator testing full period

Write a program to demonstrate that for a linear congruential generator with modulus 𝑀 = 2 𝑁 and constant 𝑏 = 1, in order to achieve the full period, the multiplier 𝑎 must be equal to 4đŸ + 1. Consider 𝑁 =5, 7, and 10; and đŸ =2 and 9. You should also consider two values of the multiplier that do not match this.

My problem with this is that I have the code to run this in Python. The suggestions I have been given are

def lcg(modulus, a, c, seed):
    """Linear congruential generator."""
    while True:
        seed = (a * seed + c) % modulus
        yield seed

However, the problem does not mention the seed value, nor do I know how to tell if it will achieve a full period. Any guidance would be appreciated




Aucun commentaire:

Enregistrer un commentaire