code: def random_rotation(axis=None, rng=default_rng()):
      """Compute a random rotation as a quaternion.
      If axis is None the rotation is sampled uniformly over all possible orientations.
      Otherwise it corresponds to a random rotation around the given axis.
      """
  
      if axis is None:
          # uniform across rotation space
          # copied from pyquat.Quaternion.random to be able to use a custom rng
          r1, r2, r3 = rng.random(3)
  
          q1 = np.sqrt(1.0 - r1) * (np.sin(2 * np.pi * r2))
          q2 = np.sqrt(1.0 - r1) * (np.cos(2 * np.pi * r2))
          q3 = np.sqrt(r1) * (np.sin(2 * np.pi * r3))
          q4 = np.sqrt(r1) * (np.cos(2 * np.pi * r3))
  
          return q1, q2, q3, q4
  
      else:
          if isinstance(axis, str) and axis.upper() in ["X", "Y", "Z"]:
              axis = {
                  "X": (1.0, 0.0, 0.0),
                  "Y": (0.0, 1.0, 0.0),
                  "Z": (0.0, 0.0, 1.0),
              }[axis.upper()]
  
          quat = pyquat.Quaternion(
              axis=axis, angle=rng.uniform(0, 2 * np.pi)
          )
          return tuple(quat)
  
file_path: kubric/kubric/randomness.py
imports: import numpy
  import pyquaternion
  from typing import Optional, Tuple
  from kubric.core import color
  from kubric.core import objects
label_desc: Use image node_id 3 for calling a global function with example usage: random_rotation(axis, rng) and returns: q1,  q2,  q3,  q4, tuple