{"id":9266,"library":"pyudorandom","title":"Pyudorandom","description":"Pyudorandom is a Python library that generates pseudorandom sequences by using algebraic methods. It allows iteration over a list in a non-successive, yet deterministic way, ensuring each item is yielded exactly once. This is particularly useful when you need to mix up items without the overhead or cryptographic guarantees of true randomness, often outperforming `random.shuffle` for longer lists. The current version is 1.0.0, and releases are generally made on an as-needed basis.","status":"active","version":"1.0.0","language":"en","source_language":"en","source_url":"https://github.com/mewwts/pyudorandom","tags":["pseudorandom","deterministic","shuffle","permutation","utility","algebra"],"install":[{"cmd":"pip install pyudorandom","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The primary functions (shuffle, items, indices) are methods of the pyudorandom module itself, not directly importable symbols.","wrong":"from pyudorandom import shuffle","symbol":"pyudorandom","correct":"import pyudorandom"}],"quickstart":{"code":"import pyudorandom\n\nmy_list = [1, 5, 7, 3, 2, 8, 4, 6]\n\n# Get a new list with elements in a 'pseudorandom' order\nshuffled_list = pyudorandom.shuffle(my_list)\nprint(f\"Original list: {my_list}\")\nprint(f\"Shuffled list: {shuffled_list}\")\n\n# Iterate through items in a 'pseudorandom' order\nprint(\"\\nIterating through items:\")\nfor item in pyudorandom.items(my_list):\n    print(item)","lang":"python","description":"This example demonstrates how to use `pyudorandom.shuffle()` to obtain a new list with elements in a deterministic, non-successive order, and `pyudorandom.items()` to iterate through them."},"warnings":[{"fix":"Always understand the deterministic nature of pseudorandom generators. For cryptographic needs, use `import secrets` and functions like `secrets.randbelow()` or `secrets.token_hex()`.","message":"Pyudorandom generates pseudorandom numbers deterministically, meaning given the same input, it will always produce the same sequence. It is not suitable for cryptographic purposes or applications requiring true unpredictability. For security-sensitive randomness, use Python's `secrets` module.","severity":"gotcha","affected_versions":"All"},{"fix":"Benchmark for your specific use case. For small lists where performance is critical, `random.shuffle` might be a better choice. `pyudorandom` is optimized for significantly longer lists.","message":"For very small lists, `pyudorandom` might be slower than Python's built-in `random.shuffle`. This is due to its internal mechanism which involves finding a number `m` coprime to the list's length `n`.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"The `shuffle` function is a method of the `pyudorandom` module itself. You should `import pyudorandom` and then call `pyudorandom.shuffle(my_list)`.","cause":"Attempting to import `shuffle` directly as if it were a top-level function in the module.","error":"ImportError: cannot import name 'shuffle' from 'pyudorandom'"},{"fix":"Ensure you pass an iterable (e.g., a list or tuple) to `pyudorandom.shuffle()` or `pyudorandom.items()`. For example, `pyudorandom.shuffle([1, 2, 3])` works, but `pyudorandom.shuffle(123)` does not.","cause":"Passing a non-iterable object (like an integer) to `pyudorandom.shuffle()` or `pyudorandom.items()`, which expect an iterable (e.g., list, tuple, string).","error":"TypeError: object of type 'int' has no len()"}]}