-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.
– Woss
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
– Marcos Henrique Duarte