code: def check_random_state(seed=None):
      """Turn `seed` into a `numpy.random.Generator` instance.
  
      Parameters
      ----------
      seed : {None, int, `numpy.random.Generator`,
              `numpy.random.RandomState`}, optional
  
          If `seed` is None the `numpy.random.Generator` singleton is used.
          If `seed` is an int, a new ``Generator`` instance is used,
          seeded with `seed`.
          If `seed` is already a ``Generator`` or ``RandomState`` instance then
          that instance is used.
  
      Returns
      -------
      seed : {`numpy.random.Generator`, `numpy.random.RandomState`}
          Random number generator.
  
      """
      if seed is None or isinstance(
          seed, (numbers.Integral, np.integer)
      ):
          if not hasattr(np.random, "Generator"):
              # This can be removed once numpy 1.16 is dropped
              msg = (
                  "NumPy 1.16 doesn't have Generator, use either "
                  "NumPy >= 1.17 or `seed=np.random.RandomState(seed)`"
              )
              raise ValueError(msg)
          return np.random.default_rng(seed)
      elif isinstance(seed, np.random.RandomState):
          return seed
      elif isinstance(seed, np.random.Generator):
          # The two checks can be merged once numpy 1.16 is dropped
          return seed
      else:
          raise ValueError(
              "%r cannot be used to seed a numpy.random.Generator"
              " instance" % seed
          )
  
imports: from __future__ import annotations
  import os
  import copy
  import numbers
  from abc import ABC, abstractmethod
  import math
  from typing import ClassVar, List, Optional, overload, TYPE_CHECKING
  import warnings
  import numpy
  import scipy.stats
  from scipy._lib._util import rng_integers
  from scipy.stats._sobol import initialize_v, _cscramble, _fill_p_cumulative, _draw, _fast_forward, _categorize, initialize_direction_numbers, _MAXDIM, _MAXBIT
  from scipy.stats._qmc_cy import _cy_wrapper_centered_discrepancy, _cy_wrapper_wrap_around_discrepancy, _cy_wrapper_mixture_discrepancy, _cy_wrapper_l2_star_discrepancy, _cy_wrapper_update_discrepancy
label_desc: Use image node_id 3 for calling a global function with example usage: check_random_state(seed) and returns: np, seed, seed