Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RaceRandom

Generator of random numbers based on intentional data races

⚠️ Experimental Research Project

This is an EDUCATIONAL project - NOT for production use!

Current version uses intentional data race on std::mt19937 internal state. This provides interesting statistical properties but:

  • Not production-safe
  • Compiler/implementation dependent
  • May cause undefined behavior
  • Not cryptographically secure

🚀 Quick Start - Just download "src/RaceRandom.h" and include it

#include "RaceRandom.h"

DataRaceGenerator generator(3, 50000);  // 3 threads, 50K iterations
size_t random_value = generator.generate();

🔬 How It Works

  • Threads compete for a non-atomic variable victim
  • Threads compete for the internal state of std::mt19937
  • Controlled chaos creates unique hardware-dependent sequences
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<size_t> dis(0, module - 1);
std::vector<std::thread> pool;
for (size_t i = 0; i < threads_nums; ++i) {
	pool.emplace_back([&]() {for (size_t i = 1; i < iterations_limit; ++i) {
		victim += dis(gen);
	} });
	
}

📊 Statistical Validation

  • According to ten uniformity tests (χ² test), the generator produces statistically uniform distribution:
  • Average χ²: 1005.056 (theoretical ideal: 1000). But it can be different on your computer.
Test 1: χ² = 1001.68
Test 2: χ² = 1012.32
Test 3: χ² = 985.04
Test 4: χ² = 1027.8
Test 5: χ² = 955.84
Test 6: χ² = 984.76
Test 7: χ² = 1052.48
Test 8: χ² = 1068.4
Test 9: χ² = 987.32
Test 10: χ² = 974.92
  • You can run your tests by yourself using "src/RaceRandom.cpp" or "src/Tests.h"

🎯 Research Significance

  • This project demonstrates that data races, typically considered bugs, can be harnessed to create functional random number generators with statistically valid properties.

About

Generator of random numbers based on data races

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages