lundi 17 décembre 2018

How to use the constant outcome of a random formed function in python

let's look at the example blow

import numpy as np

def Test2(t):                     
    ran=np.random.randint(5)
    return t-ran

def Test3(t):                     
    test2=Test2(t)
    return t**2-test2

a1=Test3(1.0)                    
a2=Test3(1.0)
a3=Test3(1.0)
print(a1==a2,a1==a3,a2==a3)  

the answer is false, since every time when i call Test3() it goes through the random part in Test2() and give me a different result. So how can i use the same Test3() for further calculating, that means i only want go through once Test2() and get a constant Test3().
Because i need Test3() for more calculating for instance finding roots, that means i need to call Test3() many times later.




Aucun commentaire:

Enregistrer un commentaire