2025-01-13 15:07:30 +01:00
2025-01-13 15:07:30 +01:00
2025-01-13 15:07:30 +01:00
2025-01-13 15:07:30 +01:00
2025-01-13 15:07:30 +01:00
2025-01-13 15:07:30 +01:00
2025-01-13 15:07:30 +01:00
2025-01-13 15:07:30 +01:00
2025-01-13 15:07:30 +01:00
2025-01-13 15:07:30 +01:00

LLM-Based Random Number Generator

This project demonstrates how to use a Large Language Model (LLM) to generate pseudo-random numbers by hashing its text outputs.

Features

  • Uses LLM outputs for randomness.
  • Hashing ensures uniform distribution.
  • Modular design for extensibility.
  • Includes unit tests and entropy analysis.

Why

This is just a fun experiment to see if we can use LLMs to generate random numbers. It builds on the idea that LLMs outputs are difficult to predict and can be used to generate random numbers as hashing their outputs will generate different numbers.

How to Run

  1. Install dependencies:

    pip install -r requirements.txt
    
  2. Run the experiment:

    python main.py
    
  3. Run tests:

    python -m unittest discover tests/ -v
    

Dependencies

  • ollama
  • numpy
  • tqdm

Entropy Analysis

The project includes entropy testing to ensure quality randomness. For our range (1-100), the entropy values mean:

  • 6.64 bits: Theoretical maximum (perfect uniformity)
  • 5-6 bits: Very good randomness
  • 3-4 bits: Moderate randomness
  • 1-2 bits: Poor randomness
  • 0 bits: No randomness

Our implementation typically achieves entropy values above 5 bits, indicating good randomness quality comparable to standard pseudo-random number generators (Python's random.randint() achieves ~6.2-6.4 bits).

Example entropy test results using the test_entropy.py file:

INFO:test_entropy:
Final entropy value: 5.253660689688187
INFO:test_entropy:Checking if entropy (5.253660689688187) > 3
ok

Notes

  • This approach is not suitable for cryptographic applications.
  • The LLM response length is limited to 50 tokens for performance.
  • First run might be slower due to model loading.
Description
No description provided
Readme
Languages
Python 100%