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

Uploaded Python 3

File details

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

File metadata

  • Download URL: lazy_fisher_yates_shuffler-1.0.4.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.2 Darwin/25.1.0

File hashes

Hashes for lazy_fisher_yates_shuffler-1.0.4.tar.gz
Algorithm Hash digest
SHA256 141dac0c031fbf868b3f1fe52f39ef836caf885476e714602fd85bec33e769e9
MD5 6aaf4a151132e881681a77bbe3260de8
BLAKE2b-256 c0a03faf54ccb3623a92e9d969425e8e64e57908f6989a472e905d6c110481a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lazy_fisher_yates_shuffler-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a52dfdc3a6bbeae92cb616a612ef3eb196c06015ea46d23ecef45c818ca7992d
MD5 b271a8e6e47a1d8b90f1d11c5cf8d241
BLAKE2b-256 de55fe53ed79d30270abaf5f823b43d664e9cbddfb68a3a58aedc197a837d18d

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