Lazy Fisher-Yates shuffler
Project description
lazy-fisher-yates-shuffler
Implementation of lazy Fisher-Yates shuffle using a binary tree to manage struck entries. The principal class is Shuffler, which maps an index to a value and vice versa, where the association between an index and a value is randomly determined the first time the index-to-value mapping is requested. The reverse value-to-index mapping is possible only after the corresponding index-to-value mapping is determined.
Installation
pip install lazy-fisher-yates-shuffler
Usage
"""
Sample code.
"""
from lazy_fisher_yates_shuffler import Shuffler
# Construct a 1,000-element non-cyclic shuffler.
shuffler = Shuffler(1000, False)
# Determine the value at a given index.
index = 10
value = shuffler.value_at(10)
print(value)
# Shuffler is reversible.
assert index == shuffler.index_of(value)
# Iterate over the entire range of the shuffler (0-999).
# Values will be randomly distributed and no two will be identical.
for value in shuffler:
print(value)
# Construct a 1,000-element cyclic shuffler.
shuffler = Shuffler(1000, True)
# Iterate over the entire range of the shuffler (0-999).
# Values will be randomly distributed and cyclic: each value is the index of the next value.
# Last value is first index (0).
for value in shuffler:
print(value)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lazy_fisher_yates_shuffler-1.0.1.tar.gz.
File metadata
- Download URL: lazy_fisher_yates_shuffler-1.0.1.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Darwin/23.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cd0252990541e05caa11a91ddb8ab318575e2828f221959420bc14de6cd2d20
|
|
| MD5 |
ad4f06ae09637e2a4e3d98ea845bf4c7
|
|
| BLAKE2b-256 |
29858a94636fcbc6e768c5e7f2a6e345248de7fec2216218cfe46a645d880a6a
|
File details
Details for the file lazy_fisher_yates_shuffler-1.0.1-py3-none-any.whl.
File metadata
- Download URL: lazy_fisher_yates_shuffler-1.0.1-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Darwin/23.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92fbeac0ec07902fb2a892c8b6523a80396b8cedaa5473c845a9899787144fda
|
|
| MD5 |
b1257386b4515fceb04744a2f84492d1
|
|
| BLAKE2b-256 |
d847fc09d46fe0642d31099e01c9ecb16c4383ee1855b5a6fd03a4e7b87d669b
|