A simple application to validate and assess the quality of random number sequences using statistical tests.
This application consists of:
- Backend: Rust-based validation logic that analyzes random number sequences
- Frontend: Clean web interface for submitting numbers and viewing results
- NIST Integration: Wrapper for the NIST Statistical Test Suite (optional)
- Parse and validate sequences of random numbers
- Calculate quality metrics including:
- Bit balance (distribution of 0s and 1s)
- Runs test (pattern analysis)
- Overall quality score (0-100%)
- Simple web interface for easy testing
- Extensible architecture for NIST test suite integration
- Rust (1.70 or newer)
- Cargo (comes with Rust)
- Clone the repository:
git clone <repository-url>
cd randomnumbervalidator- Run the application:
make runOr manually:
cargo run --bin server- Open your browser to:
http://127.0.0.1:3000
- Enter numbers separated by any delimiter (e.g.,
42, 17, 89, 3, 56or42\n17\n89\n3\n56) and click "Validate Numbers"
The application includes comprehensive logging. Control log level with the RUST_LOG environment variable:
# Info level (default)
cargo run --bin server
# Debug level (detailed logs)
RUST_LOG=debug cargo run --bin server
# Trace level (very detailed, including HTTP requests)
RUST_LOG=trace cargo run --bin server
# Specific module logging
RUST_LOG=randomnumbervalidator=debug,tower_http=info cargo run --bin serverLog output includes:
- Server startup and shutdown events
- HTTP request/response logging
- Validation request details
- NIST test execution progress
- Error conditions and warnings
make help # Show all available commands
make run # Build and run the server
make test # Run all tests
make build # Build the release version
make clean # Clean build artifacts
make dev # Run with auto-reload (requires cargo-watch)Run all tests:
make testOr with cargo:
cargo testRun tests with verbose output:
cargo test -- --nocapturerandomnumbervalidator/
├── src/
│ ├── lib.rs # Core validation logic
│ ├── nist_wrapper.rs # NIST test suite wrapper
│ └── bin/
│ └── server.rs # Web server
├── static/
│ └── index.html # Frontend interface
├── tests/
│ └── integration_test.rs # Integration tests
├── nist/ # NIST Statistical Test Suite
│ └── sts-2.1.2/
├── Makefile # Build and run commands
└── Cargo.toml # Rust dependencies
- Input Parsing: Takes comma-separated integers and converts them to binary representation
- Quality Analysis:
- Calculates bit balance (equal distribution of 0s and 1s)
- Performs runs test (checks for patterns)
- Combines metrics into overall quality score
- Results: Displays quality score and validation status
The application uses the NIST Statistical Test Suite by default for comprehensive randomness analysis.
Build the NIST test suite:
make nistOr manually:
cd nist/sts-2.1.2/sts-2.1.2
makeFrom the Web Interface:
- Enter your numbers (minimum 4 numbers for 100+ bits)
- Click "Validate Numbers"
- Results will include detailed NIST test analysis
NIST tests are always enabled and run automatically on all validations.
From the API:
# NIST tests run by default
curl -X POST http://127.0.0.1:3000/api/validate \
-H "Content-Type: application/json" \
-d '{"numbers":"42,17,89,3,56,91,23,67"}'
The NIST integration runs 15 different statistical tests including:
- Frequency (Monobit) Test
- Block Frequency Test
- Cumulative Sums Test
- Runs Test
- Longest Run of Ones Test
- Binary Matrix Rank Test
- Discrete Fourier Transform Test
- Non-overlapping Template Matching Test
- Overlapping Template Matching Test
- Maurer's Universal Statistical Test
- Approximate Entropy Test
- Random Excursions Test
- Random Excursions Variant Test
- Serial Test
- Linear Complexity Test
Results include:
- Pass/Fail status for each test
- Average p-values
- Overall success rate
Validates a sequence of random numbers.
Request:
{
"numbers": "42, 17, 89, 3, 56"
}Note: NIST statistical tests always run for all validations. The input must contain at least 100 bits of data for NIST tests to run successfully.
Response:
{
"valid": true,
"quality_score": 0.75,
"message": "Analyzed 160 bits",
"nist_results": "NIST Statistical Tests Summary\n================================\nTests Passed: 12/15\nSuccess Rate: 80.0%\n..."
}Response includes:
- Basic quality score (0.0 to 1.0)
- Pass/fail validation
- Detailed NIST test results with pass/fail status and p-values for all 15 tests
- Start the server:
make run - Open http://127.0.0.1:3000
- Try these examples:
- Good randomness:
42, 17, 89, 3, 56, 91, 23, 67, 14, 88 - Poor randomness:
1, 1, 1, 1, 1, 1, 1, 1 - Large sequence: Generate 50+ random numbers
- Good randomness:
Note: NIST tests run automatically on all validations and may take 3-5 seconds.
# NIST tests run by default
curl -X POST http://127.0.0.1:3000/api/validate \
-H "Content-Type: application/json" \
-d '{"numbers":"42,17,89,3,56"}'Server won't start:
- Check if port 3000 is available
- Try
cargo cleanand rebuild - Enable debug logging:
RUST_LOG=debug cargo run --bin server
Tests failing:
- Ensure you're using Rust 1.70 or newer
- Run
cargo updateto get latest dependencies
NIST tests not working:
- The NIST test suite requires compilation:
make nist - Check logs with
RUST_LOG=debugto see detailed error messages - Verify the assess binary exists:
ls nist/sts-2.1.2/sts-2.1.2/assess
Debugging issues:
- Enable detailed logging:
RUST_LOG=debug cargo run --bin server - Check logs for error messages and stack traces
- Logs show: request details, validation progress, NIST execution, errors
Deploy to Google Cloud Platform (GCP) for $0/month using the Always Free tier.
# One command to deploy everything
./deploy.shThis will:
- ✅ Auto-detect your GCP project and repository
- ✅ Deploy VM with PostgreSQL database locally on the instance
- ✅ Build and start the application
- ✅ Configure automatic database migrations
- ✅ Show you the application URL
No configuration files to edit! Just run the script.
# Pull latest code and rebuild
./update.sh# Remove all GCP resources
./destroy.sh- GCP e2-micro VM - Always Free tier eligible
- PostgreSQL database - Running locally on the VM (no extra cost)
- Static IP - Free while VM is running
- Automatic backups - Database on persistent disk
- Application logging - All queries logged to database
Total cost: $0/month ✅
- Install gcloud CLI
- Install Terraform
- Configure GCP project:
gcloud auth login gcloud config set project YOUR_PROJECT_ID
All validation requests are automatically logged to PostgreSQL:
- Timestamp, client IP, user agent
- Random numbers submitted (first 5KB)
- Validation results and quality scores
- NIST test results and p-values
- Processing time
Query the database:
gcloud compute ssh randomvalidator-instance --zone=us-central1-a
sudo -u postgres psql randomvalidatorSee DATABASE.md for query examples and schema details.
-
Automated NIST test suite integrationCOMPLETED -
Flexible input delimiter supportCOMPLETED -
Cloud deployment configurationCOMPLETED - Support for different input formats (binary, hex)
- Additional custom statistical tests
- Test result visualization with charts
- Batch processing capabilities
- API rate limiting and authentication
- Caching of NIST results for repeated tests
See LICENSE file for details.