mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 07:22:01 +00:00
add random number genreator
This commit is contained in:
parent
1c06958238
commit
c29cd77567
1 changed files with 23 additions and 0 deletions
23
src/Random.h
Normal file
23
src/Random.h
Normal 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_
|
Loading…
Add table
Add a link
Reference in a new issue