how to make the function follow a sequence?

-1
def fnum_aleatorio():
    a=22695477
    b=1
    m=2**32 
    semente=3
    num= semente 
    num_aleatorio = (num*a + b)%m  
    if num_aleatorio <= m//2:
        return 0
    else:
        return 1

I have this function, I want it to return 0 or 1 depending on the random number created. I have a, b, semente e m as fixed parameters! I'm trying to make a sequence of random numbers by the method of linear congruences. that is, my num_aleatorio should change. theoretically, this function should create a logical sequence that accompanies num_aleatorio = (num*a + b)%m , but I do not know how to do that. type, the next time I called the function, num would become num_aleatório old

    
asked by anonymous 26.03.2018 / 20:41

1 answer

-1

Turn these numbers to parameters and pass random numbers whenever you call the function, if you put the same numbers will always return the same thing, I advise you to pick up the system time to generate random numbers but as I do not know what is building I did not give the example:

def fnum_aleatorio(int a, in b, int semente):
m=2**32 
num_aleatorio = (semente*a + b)%m  
if num_aleatorio <= m//2:
    return 0
else:
    return 1

Remember to always change the numbers that you pass in the parameter, put it in a for and make the numbers increase or decrease, make some of the parameters change value.

    
26.03.2018 / 20:53