Repository: ManimCommunity/manim
File: manim/utils/color/core.py (Python)

Code before:
    curr_rgb = color_to_rgb(random_color())
    new_rgb = 0.5 * (curr_rgb + np.ones(3))
    return ManimColor(new_rgb)


def random_color() -> ManimColor:
    """Return a random :class:`ManimColor`.

    .. warning::
        This operation is very expensive. Please keep in mind the performance loss.

    Returns
    -------
    ManimColor
        A random :class:`ManimColor`.
    """
    return RandomColorGenerator().next()


class RandomColorGenerator:
    """
    A generator for producing random colors from a given list of Manim colors,
    optionally in a reproducible sequence using a seed value.

    When initialized with a specific seed, this class produces a deterministic
    sequence of `ManimColor` instances. If no seed is provided, the selection is
    non-deterministic using Python’s global random state.

    Parameters
    ----------
    seed : int | None, optional
        A seed value to initialize the internal random number generator.
        If None (default), colors are chosen using the global random state.

    sample_colors : list[ManimColor], optional
        A custom list of Manim colors to sample from. Defaults to the full Manim color palette.

    Examples
    --------
    Without a seed (non-deterministic):
    >>> from manim import RandomColorGenerator, ManimColor, RED, GREEN, BLUE
    >>> rnd = RandomColorGenerator()
    >>> isinstance(rnd.next(), ManimColor)
    True

    With a seed (deterministic sequence):
    >>> rnd = RandomColorGenerator(42)
    >>> rnd.next()
    ManimColor('#ECE7E2')
    >>> rnd.next()
    ManimColor('#BBBBBB')

Review comment (suggestion):
```suggestion
    sequence of :class:`.ManimColor` instances. If no seed is provided, the selection is
```

Code after:
    """
    curr_rgb = color_to_rgb(random_color())
    new_rgb = 0.5 * (curr_rgb + np.ones(3))
    return ManimColor(new_rgb)


def random_color() -> ManimColor:
    """Return a random :class:`ManimColor`.

    Returns
    -------
    ManimColor
        A random :class:`ManimColor`.
    """
    return RandomColorGenerator._random_color()


class RandomColorGenerator:
    _singleton: RandomColorGenerator | None = None
    """A generator for producing random colors from a given list of Manim colors,
    optionally in a reproducible sequence using a seed value.

    When initialized with a specific seed, this class produces a deterministic
    sequence of :class:`.ManimColor` instances. If no seed is provided, the selection is
    non-deterministic using Python’s global random state.

    Parameters
    ----------
    seed
        A seed value to initialize the internal random number generator.
        If ``None`` (the default), colors are chosen using the global random state.

    sample_colors
        A custom list of Manim colors to sample from. Defaults to the full Manim
        color palette.

    Examples
    --------
    Without a seed (non-deterministic)::

        >>> from manim import RandomColorGenerator, ManimColor, RED, GREEN, BLUE
        >>> rnd = RandomColorGenerator()
        >>> isinstance(rnd.next(), ManimColor)
        True

    With a seed (deterministic sequence)::

        >>> rnd = RandomColorGenerator(42)
        >>> rnd.next()
        ManimColor('#ECE7E2')
        >>> rnd.next()