MCPcopy Index your code
hub / github.com/python/cpython / token_hex

Function token_hex

Lib/secrets.py:47–58  ·  view source on GitHub ↗

Return a random text string, in hexadecimal. The string has *nbytes* random bytes, each byte converted to two hex digits. If *nbytes* is ``None`` or not supplied, a reasonable default is used. >>> token_hex(16) #doctest:+SKIP 'f9bf78b9a18ce6d46a0cd2b0b86df9da'

(nbytes=None)

Source from the content-addressed store, hash-verified

45 return _sysrand.randbytes(nbytes)
46
47def token_hex(nbytes=None):
48 """Return a random text string, in hexadecimal.
49
50 The string has *nbytes* random bytes, each byte converted to two
51 hex digits. If *nbytes* is ``None`` or not supplied, a reasonable
52 default is used.
53
54 >>> token_hex(16) #doctest:+SKIP
55 'f9bf78b9a18ce6d46a0cd2b0b86df9da'
56
57 """
58 return token_bytes(nbytes).hex()
59
60def token_urlsafe(nbytes=None):
61 """Return a random URL-safe text string, in Base64 encoding.

Callers

nothing calls this directly

Calls 2

token_bytesFunction · 0.85
hexMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…