mardi 2 février 2021

Generating same random seed [duplicate]

I am trying to simulate an N-body problem and for testing want to be able to generate the same random positions of particles with in a sphere each time a run the code. Is there a way to implement this into my code below using a random seed function?

The code below is just for generating N bodies in random positions in a sphere of radius R.

for i in range(N):
    
    phi = np.random.uniform(0,2*np.pi)
    costheta = np.random.uniform(-1,1)
    u = np.random.uniform(0,1)
    
    theta = np.arccos( costheta )
    r = R * (u)
    
    
    x = r * np.sin( theta) * np.cos( phi )
    y = r * np.sin( theta) * np.sin( phi )
    z = r * np.cos( theta )

    P[i] = (x,y,z)



Aucun commentaire:

Enregistrer un commentaire