lundi 25 avril 2016

random 6-sided dice roll looped 30 times

Hi i'm trying to loop this code 30 times using a random 6 sided dice roll and make a scatter cloud in the tirangle. I got it to give me 2 points but i cant figure out how to loop it after that

import numpy as np
import pylab as plt




a=1.0
h=np.sqrt(3)/2.0*a
edgepoint[0,]=[-1/2.*a, 0]
edgepoint[1,]=[1/2.*a, 0]
edgepoint[2,]=[0, h]
x=edgepoint[[0,1,2,0],0]
y=edgepoint[[0,1,2,0],1]
plt.plot(x,y)

# seed with a first random point, first the x-axis
x0=np.random.uniform(low=-1/2.0*a,high=1/2.0*a,size=1)
# now the y-coordinate, for this we need to define an upper
# limit for the random number
# per default np.random.uniform() returns numbers between 0 and 1
if (x0>=0):
    ymax=h-x0*2*h/a
else:
    ymax=(a/2+x0)*2*h/a

y0=np.random.uniform(low=0.,high=ymax,size=1)
p0=np.array([x0,y0])
plot_point(p0)

test=np.random.random_integers(0,2,1)
newx=x[test]
newy=y[test]
pnew=np.array([newx,newy])

p2=step(p0,pnew)
plot_point(p2,ic=1)




Aucun commentaire:

Enregistrer un commentaire