I want to study the behavior of the Windows pseudorandom number generator.
I can get a single random integer between 0 and 2^15 like this:
from subprocess import check_output
check_output('echo %random%', shell=True)
yields
b'28174\r\n'
But when I try to put this command in a list comprehension, it only sends the command to the OS once:
from subprocess import check_output
def rwin(n):
return [int(check_output('echo %random%', shell=True)[:-2]) for i in range(n)]
rwin(12)
yields
[27511,
27511,
27514,
27514,
27514,
27514,
27514,
27514,
27514,
27514,
27514,
27514]
I would like 12 different random numbers instead. My setup info is Python 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]
.
The answers to similar questions have suggested workarounds (e.g. using the time
module instead of subprocess
), which won't work for me as my goal is to interface directly with Windows's PRNG.