Return a random byte string containing *nbytes* bytes. If *nbytes* is ``None`` or not supplied, a reasonable default is used. >>> token_bytes(16) #doctest:+SKIP b'\\xebr\\x17D*t\\xae\\xd4\\xe3S\\xb6\\xe2\\xebP1\\x8b'
(nbytes=None)
| 31 | DEFAULT_ENTROPY = 32 # number of bytes to return by default |
| 32 | |
| 33 | def token_bytes(nbytes=None): |
| 34 | """Return a random byte string containing *nbytes* bytes. |
| 35 | |
| 36 | If *nbytes* is ``None`` or not supplied, a reasonable |
| 37 | default is used. |
| 38 | |
| 39 | >>> token_bytes(16) #doctest:+SKIP |
| 40 | b'\\xebr\\x17D*t\\xae\\xd4\\xe3S\\xb6\\xe2\\xebP1\\x8b' |
| 41 | |
| 42 | """ |
| 43 | if nbytes is None: |
| 44 | nbytes = DEFAULT_ENTROPY |
| 45 | return _sysrand.randbytes(nbytes) |
| 46 | |
| 47 | def token_hex(nbytes=None): |
| 48 | """Return a random text string, in hexadecimal. |
no test coverage detected
searching dependent graphs…