Set the random seed inside of a context manager. Parameters ---------- seed : int The seed to set Notes ----- This function is useful when you want to set a random seed but not affect the random state of other functions using the random module.
(seed)
| 52 | |
| 53 | @contextlib.contextmanager |
| 54 | def random_seed(seed): |
| 55 | """Set the random seed inside of a context manager. |
| 56 | |
| 57 | Parameters |
| 58 | ---------- |
| 59 | seed : int |
| 60 | The seed to set |
| 61 | |
| 62 | Notes |
| 63 | ----- |
| 64 | This function is useful when you want to set a random seed but not affect |
| 65 | the random state of other functions using the random module. |
| 66 | """ |
| 67 | original_state = random.getstate() |
| 68 | random.seed(seed) |
| 69 | try: |
| 70 | yield |
| 71 | finally: |
| 72 | random.setstate(original_state) |
| 73 | |
| 74 | |
| 75 | def randdecimal(precision, scale): |
nothing calls this directly
no outgoing calls
no test coverage detected