MCPcopy Create free account
hub / github.com/google-research/language / random_string

Function random_string

language/serene/util.py:128–144  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

126
127
128def 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…