|
1 | 1 | # TrueEntropy 🎲 |
2 | 2 |
|
3 | | -[](https://badge.fury.io/py/trueentropy) |
| 3 | +[](https://github.com/medeirosdev/TrueEntropy-PyLib/actions/workflows/ci.yml) |
| 4 | +[](https://pypi.org/project/trueentropy/) |
| 5 | +[](https://pypi.org/project/trueentropy/) |
4 | 6 | [](https://www.python.org/downloads/) |
5 | 7 | [](https://opensource.org/licenses/MIT) |
6 | 8 | [](https://github.com/psf/black) |
| 9 | +[](https://github.com/astral-sh/ruff) |
7 | 10 |
|
8 | 11 | **True randomness from real-world entropy sources.** |
9 | 12 |
|
@@ -75,6 +78,79 @@ for _ in range(1000): |
75 | 78 | trueentropy.stop_collector() |
76 | 79 | ``` |
77 | 80 |
|
| 81 | +## Offline Mode |
| 82 | + |
| 83 | +TrueEntropy can operate without network access using local entropy sources only. |
| 84 | + |
| 85 | +### Sources by Network Requirement |
| 86 | + |
| 87 | +| Source | Requires Network | Description | |
| 88 | +|--------|------------------|-------------| |
| 89 | +| **Timing Jitter** | ❌ No | CPU timing variations | |
| 90 | +| **System State** | ❌ No | RAM, processes, CPU metrics | |
| 91 | +| **Network Latency** | ✅ Yes | Ping response times | |
| 92 | +| **External APIs** | ✅ Yes | Earthquakes, crypto prices | |
| 93 | +| **Weather Data** | ✅ Yes | OpenWeatherMap / wttr.in | |
| 94 | +| **Quantum Random** | ✅ Yes | random.org / ANU QRNG | |
| 95 | + |
| 96 | +### Enabling Offline Mode |
| 97 | + |
| 98 | +```python |
| 99 | +import trueentropy |
| 100 | + |
| 101 | +# Enable offline mode (disables all network-dependent sources) |
| 102 | +trueentropy.configure(offline_mode=True) |
| 103 | + |
| 104 | +# Generate random numbers using local sources only |
| 105 | +value = trueentropy.random() |
| 106 | +number = trueentropy.randint(1, 100) |
| 107 | + |
| 108 | +# Check which sources are active |
| 109 | +health = trueentropy.health() |
| 110 | +print(f"Offline mode: {health['offline_mode']}") |
| 111 | +for source, info in health['sources'].items(): |
| 112 | + status = "✓" if info['enabled'] else "○" |
| 113 | + print(f" {status} {source}") |
| 114 | +``` |
| 115 | + |
| 116 | +### Selective Source Configuration |
| 117 | + |
| 118 | +```python |
| 119 | +import trueentropy |
| 120 | + |
| 121 | +# Disable only specific sources |
| 122 | +trueentropy.configure( |
| 123 | + enable_weather=False, # Disable weather API |
| 124 | + enable_radioactive=False, # Disable quantum sources |
| 125 | +) |
| 126 | + |
| 127 | +# Or enable only fast local sources |
| 128 | +trueentropy.configure( |
| 129 | + offline_mode=True, # Disable all network sources |
| 130 | + enable_timing=True, # Keep timing jitter |
| 131 | + enable_system=True, # Keep system state |
| 132 | +) |
| 133 | + |
| 134 | +# Reset to defaults (all sources enabled) |
| 135 | +trueentropy.reset_config() |
| 136 | +``` |
| 137 | + |
| 138 | +### Health Monitoring in Offline Mode |
| 139 | + |
| 140 | +```python |
| 141 | +from trueentropy import get_pool |
| 142 | +from trueentropy.health import print_health_report |
| 143 | + |
| 144 | +# Configure offline mode |
| 145 | +trueentropy.configure(offline_mode=True) |
| 146 | + |
| 147 | +# View detailed health report with source status |
| 148 | +print_health_report(get_pool()) |
| 149 | +``` |
| 150 | + |
| 151 | +> **Note**: Offline mode provides reduced entropy diversity. For security-critical applications, consider using all available sources when network access is available. |
| 152 | +
|
| 153 | + |
78 | 154 | ## Advanced Features |
79 | 155 |
|
80 | 156 | ### Async Support |
|
0 commit comments