Return a moderately randomized string, possibly with a prefix. Helpful for generating random directories to write different models to Args: prefix: If not None, prefix this to the random string Returns: Random string, perhaps with a prefix
(*, prefix = None)
| 126 | |
| 127 | |
| 128 | def random_string(*, prefix = None): |
| 129 | """Return a moderately randomized string, possibly with a prefix. |
| 130 | |
| 131 | Helpful for generating random directories to write different models to |
| 132 | |
| 133 | Args: |
| 134 | prefix: If not None, prefix this to the random string |
| 135 | |
| 136 | Returns: |
| 137 | Random string, perhaps with a prefix |
| 138 | """ |
| 139 | # For the use case, this is large enough (unique experiment IDs) |
| 140 | postfix = str(random.randrange(1_000_000, 2_000_000)) |
| 141 | if prefix is None: |
| 142 | return postfix |
| 143 | else: |
| 144 | return f'{prefix}-{postfix}' |
| 145 | |
| 146 | |
| 147 | @contextlib.contextmanager |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…