Q:

How to generate a random quadratic function in python

I'm attempting to create a random quadratic function to the 2nd degree in python that returns the same result every time.
Something along the lines of:
funk = lambda i : random.randint(0,10)*i**2 + random.randint(0,10)*i + random.randint(0,10)

The problem here is that calling x(5) two different times will have 2 potentially different results. Is it possible to generate a function that has the same result every time, or should I just do something like:
m2 = random.randint(0,9)
m1 = random.randint(0,9)
b = random.randint(0,9)
funk = lambda i : m2*i**2 + m1*i + b

and assign a new random number to globals m2,m1, and b every time I run it?

A:

You need to randomize coefficients only once, then save them somewhere and reuse for the following computations of the same function.
A class instance is ideal for this:
class RandomQuadratic:
    def __init__(self):
        self.a = random.randint(0,10)
        self.b = random.randint(0,10)
        self.c = random.randint(0,10)
    def __call__(self,x):
        return self.a*x**2+self.b*x+self.c

f = RandomQuadratic()
f(5)
f(5)

