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.2.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.2-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lazy_fisher_yates_shuffler-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 159cb0ecac7de7b3b6115f487a411f3f5a5be640212989b1ebc37ee3e508fa79
MD5 4e72d4904ea9bffecc3a933788da94b9
BLAKE2b-256 41f088920278495e557d7fae29e5140399d9045983a3e7692ee7dcf5cd5cb82d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lazy_fisher_yates_shuffler-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c6b005f3c4e6bf7416dbb8e8b87f4efd3f504945d08b0d6bc4c8458d02c304ab
MD5 4ac926a32f4b8b4e9d1e353db9b60913
BLAKE2b-256 ca40b71a1f2b42c54176602eeaa8abba8341c21b85248425aea2de250a73f49b

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