I want to generate a random byte string of length n in Python. For example, I want byte strings such as b"helloworld" generated. This answer gives the following code for generating random strings:
from random import choice
from string import ascii_uppercase
print(''.join(choice(ascii_uppercase) for i in range(12)))
However, this just generates strings and not byte strings.
How do I do this?
random.randbytes?secrets.token_bytes?os.urandom?bytes(choices(ascii_uppercase.encode(), k=12))?