// Define the global upward direction
vector upDirection = set(0, 1, 0);
// Calculate angle between the point normal and global up direction
float angleBetween = acos(dot(upDirection, @N));
// If the normal points downwards in the Z direction, negate the angle
if (@N.z < 0) {
angleBetween *= -1;
}
// Define the rotation axis as the X-axis
vector rotationAxis = set(1, 0, 0);
// Create a quaternion based on the angle and axis
p@orient = quaternion(angleBetween, rotationAxis);
// Get the random angle based on the point number and remap it between the user-defined min and max angles
float randomRotationAngle = fit(rand(@ptnum * 79123012265), 0, 1, chf("min_angle"), chf("max_angle"));
// Create a quaternion based on the random angle and the point normal
vector4 randomRotationQuat = quaternion(randomRotationAngle, @N);
// Combine the quaternions to get the final rotation
p@orient = qmultiply(randomRotationQuat, @orient);