I'm looking to get n random bytes as a bytearray or bytes, as os.urandom
does.
However I need to be able to set a random seed so the value is reproducable.
def urandom_from_random(rng, length):
return bytes([rng.randint(0, 255) for i in range(length)])
import random
rng = random.Random(42)
data = urandom_from_random(rng, 120)
print(data)
The script above works, but isn't very efficient.
Is there a more direct way to do this besides creating many ints and converting them to bytes?
Note:
- Making urandom return predictable results is possible on Linux, but needs root access.