lehmer.py

Created by bclerc

Created on June 09, 2018

364 Bytes

Le générateur de nombres aléatoires des calculatrices Texas Instruments : Le programme suivant génère les 5 premiers nombres, au-delà cela dépasse les capacités de Micro-Python. On peut obtenir le n-ième nombre aléatoire généré par la calculatrice avec alea(n), sauf que là encore Micro-Python jette l’éponge au-delà de n=8 … A noter qu’il y a un bug dans l’affichage de round(alea(2),10) qui affiche 16 chiffres après la virgule …


def lehmer1(n):
    if n==0:
        return 12345
    else :
        return (lehmer1(n-1)*40014)%(2**31-85)
def lehmer2(n):
    if n==0:
        return 67890
    else:
        return (lehmer2(n-1)*40692)%(2**31-249)
def alea(n):
    alea= (lehmer1(n)-lehmer2(n))%(2**31-86)
    return alea/(2**31-86)
for i in range(1,6):
    print(round(alea(i),10))

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.