code: def ensure_rng(random_state=None):
      
      if random_state is None:
          random_state = np.random.RandomState()
      elif isinstance(random_state, int):
          random_state = np.random.RandomState(random_state)
      else:
          assert isinstance(random_state, np.random.RandomState)
      return random_state
docs: Creates a random number generator based on an optional seed.  This can be
      an integer or another random state for a seeded rng, or None for an
      unseeded rng.