dnkl/foot
41
2.0k
Fork
You've already forked foot
243

generate-alt-random-writes: use python random, allow setting a seed #251

Manually merged
dnkl merged 1 commit from sterni/foot:random-seed into master 2020年12月20日 15:30:14 +01:00
Contributor
Copy link

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.
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)
Owner
Copy link

The only downside I see is that this is noticably slower. But, I think that's ok. If it turns out to be too slow, we could always adjust the number of iterations.

The only downside I see is that this is noticably slower. But, I think that's ok. If it turns out to be too slow, we could always adjust the number of iterations.
Author
Contributor
Copy link

I've found an issue when running this inside the nix sandbox, maybe you can help me figuring out a workaround and the impact:

  • random.randrange(0) raises an error
  • height and width are apparently zero inside the nix build sandbox

Does that mean testing sixels is off the table for that?

I've found an issue when running this inside the nix sandbox, maybe you can help me figuring out a workaround and the impact: * `random.randrange(0)` raises an error * `height` and `width` are apparently zero inside the nix build sandbox Does that mean testing sixels is off the table for that?
dnkl manually merged commit 1d7595d1db into master 2020年12月20日 15:30:14 +01:00
Owner
Copy link

Does that mean testing sixels is off the table for that?

No, because we don't have to pass actual values. The PGO helper binary uses a cell-width of 8px and a cell height of 15px. It also hardcodes the cols/rows to 135x67.

I think it would make sense to override width/height if --cols and --rows has been used (which you should do in a headless PGO build). I'll push a fix for that.

> Does that mean testing sixels is off the table for that? No, because we don't have to pass *actual* values. The PGO helper binary uses a cell-width of 8px and a cell height of 15px. It also hardcodes the cols/rows to 135x67. I think it would make sense to override width/height if `--cols` and `--rows` has been used (which you should do in a headless PGO build). I'll push a fix for that.
Owner
Copy link
@sterni https://codeberg.org/dnkl/foot/commit/e9dea5bb9d25bf18ffc5884e13573f8f2caf7436
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dnkl/foot!251
Reference in a new issue
dnkl/foot
No description provided.
Delete branch "sterni/foot:random-seed"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?