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.0b6.tar.gz
(13.0 kB
view hashes)
Built Distributions
Close
Hashes for smallperm-0.1.0b6-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3985889241eb4e0744ca927e84d6ee741a54d926865c7fd760106e1bdaabb5a2 |
|
MD5 | 96553df45ade4f565e0030681e9897b5 |
|
BLAKE2b-256 | 28bce7b2625ead2d6539bb6314c23ff7564f6c7e063cf299b9f7a011b1cb9d4c |
Close
Hashes for smallperm-0.1.0b6-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8aeaa05a5952d52e17a5d301fa5dea5a95adabd08a6a6147eb9b88518f3ded53 |
|
MD5 | 9d6e50a36dca754952d0617d05fd1afb |
|
BLAKE2b-256 | fa4de1135caeab84b8b46d3e8e980cf00de4897e2da0765bd1a008b7ceaa5325 |
Close
Hashes for smallperm-0.1.0b6-cp37-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 362bb10b8f3f76b9c2b5e317ebadaff230769ba0e8dfe1b7ee3f8e4ab5770044 |
|
MD5 | 3746a7c55a90358f90f0c4b3b2e42e15 |
|
BLAKE2b-256 | 543391b34103a3f2c231542891381738c280ca5ed0c09554174f2da48fe8508f |