code: def random_state(state: RandomState | None = None):
      """
      Helper function for processing random_state arguments.
  
      Parameters
      ----------
      state : int, array-like, BitGenerator, Generator, np.random.RandomState, None.
          If receives an int, array-like, or BitGenerator, passes to
          np.random.RandomState() as seed.
          If receives an np.random RandomState or Generator, just returns that unchanged.
          If receives `None`, returns np.random.
          If receives anything else, raises an informative ValueError.
  
          .. versionchanged:: 1.1.0
  
              array-like and BitGenerator object now passed to np.random.RandomState()
              as seed
  
          Default None.
  
      Returns
      -------
      np.random.RandomState or np.random.Generator. If state is None, returns np.random
  
      """
      if (
          is_integer(state)
          or is_array_like(state)
          or isinstance(state, np.random.BitGenerator)
      ):
          # error: Argument 1 to "RandomState" has incompatible type "Optional[Union[int,
          # Union[ExtensionArray, ndarray[Any, Any]], Generator, RandomState]]"; expected
          # "Union[None, Union[Union[_SupportsArray[dtype[Union[bool_, integer[Any]]]],
          # Sequence[_SupportsArray[dtype[Union[bool_, integer[Any]]]]],
          # Sequence[Sequence[_SupportsArray[dtype[Union[bool_, integer[Any]]]]]],
          # Sequence[Sequence[Sequence[_SupportsArray[dtype[Union[bool_,
          # integer[Any]]]]]]],
          # Sequence[Sequence[Sequence[Sequence[_SupportsArray[dtype[Union[bool_,
          # integer[Any]]]]]]]]], Union[bool, int, Sequence[Union[bool, int]],
          # Sequence[Sequence[Union[bool, int]]], Sequence[Sequence[Sequence[Union[bool,
          # int]]]], Sequence[Sequence[Sequence[Sequence[Union[bool, int]]]]]]],
          # BitGenerator]"
          return np.random.RandomState(state)  # type: ignore[arg-type]
      elif isinstance(state, np.random.RandomState):
          return state
      elif isinstance(state, np.random.Generator):
          return state
      elif state is None:
          return np.random
      else:
          raise ValueError(
              "random_state must be an integer, array-like, a BitGenerator, Generator, "
              "a numpy RandomState, or None"
          )
  
imports: from __future__ import annotations
  import builtins
  from collections import abc, defaultdict
  import contextlib
  from functools import partial
  import inspect
  from typing import TYPE_CHECKING, Any, Callable, Collection, Generator, Hashable, Iterable, Sequence, cast, overload
  import warnings
  import numpy
  from pandas._libs import lib
  from pandas._typing import AnyArrayLike, ArrayLike, NpDtype, RandomState, T
  from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
  from pandas.core.dtypes.common import is_array_like, is_bool_dtype, is_extension_array_dtype, is_integer
  from pandas.core.dtypes.generic import ABCExtensionArray, ABCIndex, ABCSeries
  from pandas.core.dtypes.inference import iterable_not_string
  from pandas.core.dtypes.missing import isna
label_desc: Use image node_id 26 for calling a global function with example usage: random_state(state) and returns: np, state, state, np