## simulate 500 randomly scattered pts in a diamond ## with vertices at (-1,0), (0,1), (1,0), (0,-1). z = matrix(0,ncol=2,nrow=1200) j=1 for(i in c(1:1200)){ x = runif(1)*2-1 y = runif(1)*2-1 if(abs(x)+abs(y)<1){ z[j,] = c(x,y) j = j+1 } } z2 = z[1:500,] ## but check that you have kept at least 500 pts plot(z2) plot(z2[,1],z2[,2]) lines(c(-1,0,1,0,-1),c(0,1,0,-1,0)) ## a little better: plot(c(-1,0,1,0,-1),c(0,1,0,-1,0),type="l",xlab="x",ylab="y") points(z2) diamond3 = function(k,n){ z = matrix(0,ncol=2,nrow=n) j=1 for(i in c(1:n)){ x = runif(1)*2-1 y = runif(1)*2-1 if(abs(x)+abs(y)<1){ z[j,] = c(x,y) j = j+1 } } if(j