Python Forum
About Random int - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: About Random int (/thread-30818.html)



About Random int - MertH - Nov-08-2020

Hi guys,

i have input variable x and generated random variable a

i want to x*a < 250 with the highest x*a value

I am stuck with the highest x*a value

Can you help me about that ?


RE: About Random int - bowlofred - Nov-08-2020

I don't understand "highest" in your description. If you only have one x and one a, then x*a is fixed.

You can solve directly for the maximum a that would allow the expression to be true:
x * a < 250
a < (250 / x)

So 250 / x is the maximum value a could be and the expression is still true.


RE: About Random int - MertH - Nov-08-2020

while  k != True:
    a = random.randint(1,int(250/x))
    b = random.randint(1,int(250/y))
    
    if a*b in denominator(z) and 75<x*a<250 and 75<y*b<250:
         
        print(a,b)
        print("X = ",(x*a),"Y =",(y*b))
        print(a*b)
        print("Panel sayisi:", z/(a*b))
        k = True
By the help of you i updated randint max integer but i still get some values which is below my desire because random variables are between 1 and int(250/x).I think i have to make some changes on if line to get max(x*a)<250.I cant change randint min value which is 1 because a*b must be in the list which is i generated as a denominator. Do you have any idea ?




Problem Solved. Ty for help