def random_special_unitary(
    dim: int, *, random_state: np.random.RandomState | None = None
) -> np.ndarray:
    """Returns a random special unitary distributed with Haar measure.

    Args:
        dim: The width and height of the matrix.
        random_state: A seed (int) or `np.random.RandomState` class to use when
            generating random values. If not set, defaults to using the module
            methods in `np.random`.

    Returns:
        The sampled special unitary.
    """
    r = random_unitary(dim, random_state=random_state)
    with np.errstate(divide="ignore", invalid="ignore"):
        r[0, :] /= np.linalg.det(r)
    return r
Returns a random special unitary distributed with Haar measure.

    Args:
        dim: The width and height of the matrix.
        random_state: A seed (int) or `np.random.RandomState` class to use when
            generating random values. If not set, defaults to using the module
            methods in `np.random`.

    Returns:
        The sampled special unitary.
    
cirq-core/cirq/testing/lin_alg_utils.py