code: def control_randomness(object_with_random_state: HasRandomState):
      """Seeds the randomness inside the indented block of code using `self.random_state`."""
      if object_with_random_state.random_state is None:
          yield
          return
  
      # Backup the initial random state to a variable.
      initial_rng_state = RandomState.current()
  
      # Set the random state from the object.
      object_with_random_state.random_state.set()
  
      # Yield (enter the 'with' indented block). Rng-related code will be executed here and modify
      # the state of the random number generators in the various packages.
      yield
  
      # Capture the final state of the RNG's, and save it on the object so we can "resume" at that
      # state later.
      object_with_random_state.random_state = RandomState.current()
  
      # Reset the initial state of the RNGs.
      initial_rng_state.set()
  
file_path: orion/src/orion/core/utils/random_state.py
imports: from __future__ import annotations
  import random
  from contextlib import contextmanager
  from dataclasses import dataclass, replace
  from typing import Any, Protocol
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: control_randomness(object_with_random_state) without return types