Skip to main content

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

lazy_fisher_yates_shuffler-1.0.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lazy_fisher_yates_shuffler-1.0.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file lazy_fisher_yates_shuffler-1.0.0.tar.gz.

File metadata

  • Download URL: lazy_fisher_yates_shuffler-1.0.0.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

Hashes for lazy_fisher_yates_shuffler-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f6f3961f6c27e7138ce6a0677006a895e0b8dac11ed348a4ed6c27e21ea22da7
MD5 5b9c54adeb48c1d7b2a31c53a68afcd3
BLAKE2b-256 89dd3af676c3ced48fdd4c9856a1746d6dae70beedabf629209d97b1cf7f5b2c

See more details on using hashes here.

File details

Details for the file lazy_fisher_yates_shuffler-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for lazy_fisher_yates_shuffler-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9ca8b11726beb58cfc34545c382e95272f5ad126c9770efe102169302d5a882
MD5 3471225126b5c1aa0301f64f6e5dbfb3
BLAKE2b-256 0f2a6ccace3c5e27872533377ec891124dd019dd88bd3d49eb74567bf9ec1988

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page