random byte string in python - Stack Overflow
stackoverflow.com › questions › 5495492Mar 31, 2011 · Python 3.9 adds a new random.randbytes method. This method generates random bytes: from random import randbytes randbytes(4) Output: b'\xf3\xf5\xf8\x98' Be careful though. It should be used only when you are not dealing with cryptography. As stated in the docs: This method should not be used for generating security tokens.