def random_quaternion(rand=None):
 if (rand is None):
  rand = numpy.random.rand(3)
 else:
  assert (len(rand) == 3)
 r1 = numpy.sqrt((1.0 - rand[0]))
 r2 = numpy.sqrt(rand[0])
 pi2 = (math.pi * 2.0)
 t1 = (pi2 * rand[1])
 t2 = (pi2 * rand[2])
 return numpy.array([(numpy.cos(t2) * r2), (numpy.sin(t1) * r1), (numpy.cos(t1) * r1), (numpy.sin(t2) * r2)])

def random_quaternion ( rand = None ) : if ( rand is None ) : rand = numpy . random . rand ( 3 ) else : assert ( len ( rand ) == 3 ) r1 = numpy . sqrt ( ( 1.0 - rand [ 0 ] ) ) r2 = numpy . sqrt ( rand [ 0 ] ) pi2 = ( math . pi * 2.0 ) t1 = ( pi2 * rand [ 1 ] ) t2 = ( pi2 * rand [ 2 ] ) return numpy . array ( [ ( numpy . cos ( t2 ) * r2 ) , ( numpy . sin ( t1 ) * r1 ) , ( numpy . cos ( t1 ) * r1 ) , ( numpy . sin ( t2 ) * r2 ) ] )
return uniform random unit quaternion .