static void GetUnitQuaternion(Random random, out Quaternion orientation) { //Not much cleverness involved here. This does not produce a uniform distribution over the the unit sphere. float length; do { orientation = new Quaternion( (float)random.NextDouble() * 2 - 1, (float)random.NextDouble() * 2 - 1, (float)random.NextDouble() * 2 - 1, (float)random.NextDouble() * 2 - 1); length = orientation.Length(); } while (length < 1e-7f); Unsafe.As <Quaternion, Vector4>(ref orientation) /= length; }