Libftpp
A modern C++ library
random_2D_coordinate_generator.cpp
Go to the documentation of this file.
2 
9 
15 {
16  // Seed based on time in microseconds since epoch
17  const auto now = std::chrono::system_clock::now();
18  _seed = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
19 
20  // Mix with PID to give to each process a different seed
21  _seed ^= getpid();
22 
23  _seed ^= rand();
24 
25  int x;
26  // Generated unique hash based on int x address in memory
27  _seed ^= std::hash<int*>{}(&x);
28 }
29 
31 {
32  return _seed;
33 }
34 
35 long long Random2DCoordinateGenerator::operator()(const long long& x, const long long& y)
36 {
37  return std::hash<long long>{}(_seed ^ (x * 7 - y * 13));
38 }
Random2DCoordinateGenerator()
Default constructor that initializes the seed based on the current time, process ID,...
long long operator()(const long long &x, const long long &y)