add random number genreator

This commit is contained in:
Shuo Feng 2024-03-19 23:31:04 -04:00
parent 1c06958238
commit c29cd77567
Signed by: sfeng
GPG key ID: 1E83AE6CD1C037B1

23
src/Random.h Normal file
View file

@ -0,0 +1,23 @@
#ifndef RANDOM_H_
#define RANDOM_H_
#include <chrono>
#include <random>
namespace utils {
class Random {
public:
/**
* A way to generate higher quality random number
* since C++ 11
*/
static float get() {
std::default_random_engine generator(
std::chrono::system_clock::now().time_since_epoch().count());
std::uniform_real_distribution<float> distribution(0.0f, 1.0f);
return distribution(generator);
}
};
} // namespace utils
#endif // !RANDOM_H_