Skip to main content

🎲 random-casual

pip install random-casual

random-casual is a "vintage-style" linear congruential generator (LCG) built from scratch. It combines the charm of old-school algorithms...

The algorithm processes numbers in RAM but ensures long-term persistence by asynchronously updating an encrypted state file on the hard drive in the background.

🚀 Unique Features

  • Evolving Mathematics: Unlike classic generators based on static formulas, random-casual modifies its mathematical coefficients with every single draw. This makes it virtually impossible to predict the next number from the outside.
  • Write-back Caching: Draws occur instantly in memory. The state is written to a protected binary file on the hard drive only upon reaching a specific threshold (e.g., every 500 draws), thereby preserving the SSD's lifespan.
  • Continuous Density (Evolved Decimals): Dynamic fractional accumulation provides high-precision decimal outputs, generating an incredibly wide variety of unique values ​​compared to traditional methods.
  • Tamper Resistance: The generator's state is stored in a binary file encrypted via XOR logic. If the file is externally altered, the system detects the corruption, discards the file, and performs an automatic reset by acquiring hardware entropy from CPU clock latency.
  • Hardware-sourced Randomness: The engine captures the exact state of the CPU clock (time.perf_counter_ns()) in real-time [I]. This hardware noise is injected directly into the generation process via XOR operations, rendering the output cryptographically unpredictable even in the event of a data leak involving the state file. ## 📊 Performance and Precision Benchmarks (100,000 Draws) During stress tests covering the 1–100 range over 100,000 continuous cycles, random-casual achieved remarkable statistical results, clearly outperforming Python's standard random library in terms of precision:
Metric random-casual Python Random
Execution Time ~0.17 seconds ~0.10 seconds
Deviation from Ideal Mean (50.5) 0.0042 0.2142
Unique Values ​​Generated 9,900 9,901
Peak Frequency (Most repeated value) Max 24 times (0.02%) Max 25 times (0.03%)

Note: In its best-performing session, random-casual significantly outperformed the standard Python version, coming 50 times closer to the perfect theoretical center.

⚠️ Technical Limitations and Sweet Spot (Scaling Limit) ⚠️

The engine's stability depends on the relationship between the range scale and the decimal factor. If the total scaled number exceeds the processor's bit limits for floating-point numbers (floats), computational saturation occurs.

  • Optimal conditions: Up to a scaled range with decimals=7 on a small interval (e.g., the 1–100 range with 7 decimal places works perfectly, generating over 9,900 unique values ​​and a robust distribution). * Critical point: Extending the range (e.g., 1–1000 with 7 decimal places, or any range with 8 or more decimal places) hits the hardware's floating-point precision limit. This causes the engine to collapse into a stable, periodic cycle of exactly 2,148 unique values.

Installation

pip install random-casual

Usage example

from random_casual import genera_numero

# Generate an integer between 1 and 100
integer_num = genera_numero(1, 100)
print(integer_num) # Example: 42


# Generate a decimal number (float) with 2 decimal places between 1 and 10
decimal_num = genera_numero(1, 10, decimali=2)
print(decimal_num) # Example: 5.53

# Generate a decimal number (float) with 2 decimal places between 1 and 10
decimal_num = genera_numero(1, 10, 2)
print(decimal_num) # Example: 1.51

Release files for random-casual 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for random-casual 1.0.0
File Size Uploaded
random_casual-1.0.0.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for random-casual 1.0.0
File Interpreter ABI Platform
random_casual-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.4 kB

Release files / random_casual-1.0.0.tar.gz

Download URL random_casual-1.0.0.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
407196f9c9ace67bf358a7f43df244dd510cda085abf93b094797a593287d234
BLAKE2b-256 checksum
How to use checksums
aef45e069ec0e66501fd442ca8f4651aa9f5666570cd2191071d6c02be1725ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.8

Release files / random_casual-1.0.0-py3-none-any.whl

Download URL random_casual-1.0.0-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68bdb09d9b22260df727e2f04b5225d5bf89db37d65d0e6162777c18522b8b01
BLAKE2b-256 checksum
How to use checksums
50a0b5774e8146d6000d8af76ebabb79d889b8ee88f4c77cf4022131bd9a1719
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.8

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page