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.0b7.tar.gz
(11.7 kB
view hashes)
Built Distributions
Close
Hashes for smallperm-0.1.0b7-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a45c6190218a18facb1693bb8039e7026cbde3abb8f9cb20f0f0385d73c4f5a2 |
|
MD5 | 00a2f4d74cf2157ef2f040812624bcaf |
|
BLAKE2b-256 | 47b5fc9230cfc4daaddcab9464d972ba1533abbbca7ded1d97b314b070fe1426 |
Close
Hashes for smallperm-0.1.0b7-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b234fd2c39f8e7a11ac18cbfca3b5be591513d69aeba2c954bc62b31e6e0889 |
|
MD5 | 41850f04b759aa791d9fc4356f7d1018 |
|
BLAKE2b-256 | fb53fff8171d93b19da44bff4a5e7b4f2413255bc77e9abd46e626107e66ef64 |
Close
Hashes for smallperm-0.1.0b7-cp37-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45879291f7369273f383b76b0ef527f52752373c556474ea7aa6114aea6338e8 |
|
MD5 | 90dcf2dde0130132cefdf12fa5a1b4dc |
|
BLAKE2b-256 | 33f3804c89bf0ff2a863bc8e64062a2703793a6666c88dad64aad2986214dfc8 |