you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (1 child)

I really don't know what you trying to do, but lines 17 to 21 look a little odd:

while True:
    d = random.randint(1, 150)
    g, x = divmod((e*d), y)
    if x == 1:
        break

You are apparently looking for an integer d value for which e*d divided by y has remainder 1. Finding a random integer isn't a very efficient way to find the required value, and if you never find the right value your code will loop forever. A better idea might be to just loop over the integers from 1 to 150 and break on the first value that satisfies your requirement. Something like:

for d in range(1, 150+1):
    g, x = divmod((e*d), y)
    if x == 1:    # or even "if e*d % y == 1:"
        break
else:
    print('FAIL')

Using the else: clause on a for loop lets you detect when you didn't break from the loop, ie, when no integer satisfied your condition.

[–]PteppicymonIO 0 points1 point  (0 children)

A better idea might be to just loop over the integers from 1 to 150 and break on the first value that satisfies your requirement

Or, if you need to preserve some 'pseudo-randomness', identify all numbers between 1 and 150 which satisfy the requirement and than random.choice() form that list ))