how to make the function follow a sequence?

Asked

Viewed 151 times

-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 me 0 or 1 depending on the random number created. i have a, b, semente e m as fixed parameters! I am trying to make a sequence of random numbers by the linear congruence method. ie, my num_aleatorio should keep changing. theoretically, this function should create a logical sequence that accompanies num_aleatorio = (num*a + b)%m ,but I don’t know how to do it. Like, next time I call the function, the num would become the num_aleatório ancient

  • What exactly do you expect to do with the function? You comment that the return depends on the random number created, but the number is not random. It has how to describe the problem that retains to solve with this function, therefore, perhaps, it is a case of XY problem.

  • So I have a, b, seed and m as fixed parameters! I’m trying to make a sequence of random numbers by the linear congruence method. I mean, mine at random should keep changing, but I don’t know how to do it! theoretically, this function should create a logical sequence that accompanies num_aleatorio = (num*a + b)%m , but I don’t know how to do this. like, the next time I called the function, the num would become the old random num_num

1 answer

-1

Transform these numbers to parameters and pass random numbers whenever calling the function, if you put the same numbers will always returns the same thing, I advise to take the time of the system to generate random numbers but as I do not know what this building 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 you pass in the parameter, put in a for and make the numbers increase or decrease, somehow make the parameters change value.

  • So I have a, b, seed and m as fixed parameters! I’m trying to make a sequence of random numbers by the linear congruence method. I mean, mine at random should keep changing, but I don’t know how to do it!

  • at least correct the code in a way that is valid Python.

  • Dude, I just started, I’m really lost on language. I’m here to learn. how can I leave the code so that it is valid in Python?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.