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.0.tar.gz
(17.5 kB
view hashes)
Built Distributions
Close
Hashes for smallperm-0.1.0-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fb2b69f0f174d150352a54277b56a84e58fdacf06188c0426218ce115b84c98 |
|
MD5 | 2a5ff95318a1b8fddfab86b310e606f1 |
|
BLAKE2b-256 | 2ff99930e2e74c114db0ecd6222bb02810dcd420becbedd22a45d890b70d2143 |
Close
Hashes for smallperm-0.1.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2146d9e645d61426ceaf8ba6b546fe0ca0551d7a73b28b44b13b309b4a524ad7 |
|
MD5 | 85cf935eaba0bcc33298f21bc3c24cf0 |
|
BLAKE2b-256 | 24e791439202f753f7b4f4f75e2b58d98394d077dc7eeed9949841c9d40ef4ba |
Close
Hashes for smallperm-0.1.0-cp37-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdc9652b962d57a67ecbd8df0e019c2819ad218be25dbf5e03af4f463f76e0d6 |
|
MD5 | f59db600a905b2c4ab5654e08b377c8e |
|
BLAKE2b-256 | f60a9dcfefc0232922f71a4f64a5db14a93cdb81fb077f236591bb09d0bd574f |