jeudi 6 septembre 2018

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?




Aucun commentaire:

Enregistrer un commentaire