Reputation: 143
I need to generate random 3D coordinates, so that every run has new random points. I am trying to add seed to avoid having same points every time.
So far I have tried this
from random import *
rnd = random.Random(8)
x,y,z = 7.045,23.569,63.447
x1,y1,z1 = (rnd.uniform(x-3.5,x+3.5),rnd.uniform(y-3.5,y+3.5),rnd.uniform(z-3.5,z+3.5))
newcord = [x1,y1,z1]
print newcord
What am I doing wrong?
Upvotes: 0
Views: 142
Reputation: 1095
To set the seed using your existing code:
import random as rnd
rnd.seed(8)
x,y,z = 7.045,23.569,63.447
newcord = [rnd.uniform(x-3.5,x+3.5),rnd.uniform(y-3.5,y+3.5),rnd.uniform(z-3.5,z+3.5)]
print newcord
Using the seed means each time you run the code you will get the same random numbers. This way your results are reproducible.
Upvotes: 0
Reputation: 17871
Change the second line rnd = random.Random(8)
to rnd = Random()
. Otherwise it should work fine.
Upvotes: 2