code: def random_seed(seed=None):
      """
      Runs a code block with a new seed for np, mx and python's random.
  
      Parameters
      ----------
  
      seed : the seed to pass to np.random, mx.random and python's random.
  
      To impose rng determinism, invoke e.g. as in:
  
      with random_seed(1234):
          ...
  
      To impose rng non-determinism, invoke as in:
  
      with random_seed():
          ...
  
      Upon conclusion of the block, the rng's are returned to
      a state that is a function of their pre-block state, so
      any prior non-determinism is preserved.
  
      """
  
      try:
          next_seed = np.random.randint(0, np.iinfo(np.int32).max)
          if seed is None:
              np.random.seed()
              seed = np.random.randint(0, np.iinfo(np.int32).max)
          logger = default_logger()
          logger.debug(
              "Setting np, mx and python random seeds = %s", seed
          )
          np.random.seed(seed)
          mx.random.seed(seed)
          random.seed(seed)
          yield
      finally:
          # Reinstate prior state of np.random and other generators
          np.random.seed(next_seed)
          mx.random.seed(next_seed)
          random.seed(next_seed)
  
file_path: gluon-cv/tests/unittests/common.py
imports: import sys, os, logging
  import mxnet
  import numpy
  import random
  import shutil
  from contextlib import contextmanager
  from nose.tools import make_decorator
  import tempfile
label_desc: Use image node_id 5 for calling a global function with example usage: random_seed(seed) without return types