Using Python's own PRNG should make the code cleaner and allow for
reproducible stimulus files if that is desired via setting --seed (at
least for the same versions of the script, changing the kind and/or
order of the random calls will of course impact the output in the
future).
I did the following substitutions:
rand.read(1)[0] % n and struct.unpack('@H', rand.read(2))[0] % n →
random.randrange(n)
rand.read(1)[0] → random.randrange(256)
rand.read(n) → [random.randrange(256) for _ in range(n)]
(better alternative would have been random.randbytes(n), but is only
available for Python >= 3.9, switching to this in the future will
impact output)
list[rand.read(1) % len(list)] → random.choice(list)
Unfortunately since we loose the with blocks, the unified diff is pretty unreadable.
Using Python's own PRNG should make the code cleaner and allow for
reproducible stimulus files if that is desired via setting --seed (at
least for the same versions of the script, changing the kind and/or
order of the random calls will of course impact the output in the
future).
I did the following substitutions:
* `rand.read(1)[0] % n` and `struct.unpack('@H', rand.read(2))[0] % n` →
`random.randrange(n)`
* `rand.read(1)[0]` → `random.randrange(256)`
* `rand.read(n)` → `[random.randrange(256) for _ in range(n)]`
(better alternative would have been `random.randbytes(n)`, but is only
available for Python >= 3.9, switching to this in the future will
impact output)
* `list[rand.read(1) % len(list)]` → `random.choice(list)`
Unfortunately since we loose the `with` blocks, the unified diff is pretty unreadable.