@contextmanager
def random_seed(seed):
 state = random.getstate()
 random.seed(seed)
 try:
  (yield)
 finally:
  random.setstate(state)

@ contextmanager def random_seed ( seed ) : state = random . getstate ( ) random . seed ( seed ) try : ( yield ) finally : random . setstate ( state )
temporarily change the seed of the random number generator .