Efficient O(1)-space pseudorandom permutation for large scale shuffling
Project description
smallperm
Small library to generate permutations of a list of elements using pseudo-random permutations (PRP). Uses O(1)
memory and O(1)
time to generate the next element of the permutation.
>>> from smallperm import PseudoRandomPermutation
>>> list(PseudoRandomPermutation(42, 0xDEADBEEF))
[14, 32, 25, 16, 0, 12, 5, 37, 30, 7, 40, 17, 27, 35, 21, 15, 1, 13, 38, 4, 9, 36, 20, 22, 24, 39, 41, 19, 3, 18, 8, 2, 29, 31, 6, 34, 11, 23, 26, 10, 28, 33]
API
-
Initialization:
PseudoRandomPermutation(length: int, seed: int)
- Generates a permutation of
[0, length)
usingseed
.
- Generates a permutation of
-
Usage: Iterate over the instance to get the next element of the permutation.
- Example:
list(PseudoRandomPermutation(42, 0xDEADBEEF))
- Example:
Acknowledgements
Gratefully reuses code from https://github.com/asimihsan/permutation-iterator-rs which does most of the heavy lifting. Because the heavy lifting is done in Rust, this library is very efficient.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
smallperm-0.1.0b8.tar.gz
(17.2 kB
view hashes)
Built Distributions
Close
Hashes for smallperm-0.1.0b8-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb83bb9df103acba3d673029be8434980f55c48365b76960bdc5cd4ef9dccaeb |
|
MD5 | 89309ac73e50eea5dfe3070d6c0f7f2a |
|
BLAKE2b-256 | b8e9261779c1d40cf8d87a7ca637025de1cc88d4f5bb60bb85a57c695039b549 |
Close
Hashes for smallperm-0.1.0b8-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46e4b930e278cb9a393b8ce38fa6b8d5880f88a253bbfdcea2c6156540b998ae |
|
MD5 | 6fe24c964e261a0890c62d2d07bc3664 |
|
BLAKE2b-256 | 20550dc0f565be180c5f8591344d3edd135f58bd04d35c093a41a0c14ce66dd3 |
Close
Hashes for smallperm-0.1.0b8-cp37-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37c4b5372c3493bd89f6cfd7de31d7d10b660ce4f0d008e2e76265be261a0d8c |
|
MD5 | 6d9415361c3c852fd50e31f81d0fd6d0 |
|
BLAKE2b-256 | 463e1b0dffbecb728ff568e1cfd212a3dd2bcfcb2a122a766a1273b57ed68df9 |