static public PVector random3D(PVector target,PApplet parent){
  float angle;
  float vz;
  if (parent == null) {
    angle=(float)(Math.random() * Math.PI * 2);
    vz=(float)(Math.random() * 2 - 1);
  }
 else {
    angle=parent.random(PConstants.TWO_PI);
    vz=parent.random(-1,1);
  }
  float vx=(float)(Math.sqrt(1 - vz * vz) * Math.cos(angle));
  float vy=(float)(Math.sqrt(1 - vz * vz) * Math.sin(angle));
  if (target == null) {
    target=new PVector(vx,vy,vz);
  }
 else {
    target.set(vx,vy,vz);
  }
  return target;
}

static public PVector random3D ( PVector target , PApplet parent ) { float angle ; float vz ; if ( parent == null ) { angle = ( float ) ( Math . random ( ) * Math . PI * 2 ) ; vz = ( float ) ( Math . random ( ) * 2 - 1 ) ; } else { angle = parent . random ( PConstants . TWO_PI ) ; vz = parent . random ( - 1 , 1 ) ; } float vx = ( float ) ( Math . sqrt ( 1 - vz * vz ) * Math . cos ( angle ) ) ; float vy = ( float ) ( Math . sqrt ( 1 - vz * vz ) * Math . sin ( angle ) ) ; if ( target == null ) { target = new PVector ( vx , vy , vz ) ; } else { target . set ( vx , vy , vz ) ; } return target ; }
make a new 3d unit vector with a random direction
