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(index)

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.3.tar.gz (13.7 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.3-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lazy_fisher_yates_shuffler-1.0.3.tar.gz
  • Upload date:
  • Size: 13.7 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.3.tar.gz
Algorithm Hash digest
SHA256 17c36615b4d6e3bbe4c6a57508093a9e126fd92079d524aed8658c56f9da93e5
MD5 b2b249aa1378ac99babf259b1ea3fc3d
BLAKE2b-256 c325901319e069413c6d9d790cef54b05e9001a843d02aaa63f0b496badd8e91

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lazy_fisher_yates_shuffler-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cb9a4d567f84f5a7fe30d5cf4fb8c9ef4f6f4c20e25422216df0441d08de6753
MD5 a462fd3c4a743aedf8be984d3e1aad59
BLAKE2b-256 b5617e9f4c109b42da54354ba4674b98e6cef9a82bbe61d7a19ee66de8e970b4

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