I want to evaluate an expression and regenerate the random numbers in __init__ method of Class if the condition is met. Code for that is below
import random
class RandomNumbers:
def __init__(self):
self.BASE_A = random.randint(2, 10)
self.BASE_B = random.randint(2, 10)
self.EXPONENT_N = random.randint(2, 7)
self.EXPONENT_P = random.randint(2, 7)
# Ensure result
while self.BASE_A ** self.EXPONENT_N - \
self.BASE_B ** self.EXPONENT_P == 0:
# re initiate BASE_A, BASE_B, EXPONENT_N, EXPONENT_P
pass
def generate(self):
return self.BASE_A, self.EXPONENT_N, self.BASE_B, \
self.EXPONENT_P
How can I call __init__ within __init__ if self.BASE_A ** self.EXPONENT_N - self.BASE_B ** self.EXPONENT_P == 0 ?