YAPOG  0.0.1
Yet Another Pokemon Online Game
RandomHelper.cpp
Go to the documentation of this file.
1 #include <cstdlib>
2 
4 
5 namespace yap
6 {
7  void RandomHelper::Init (uint seed)
8  {
9  srand (seed);
10  }
11 
12  int RandomHelper::GetNext (const int& min, const int& max)
13  {
14  return GetNext () % (max - min + 1) + min;
15  }
16 
17  float RandomHelper::GetNext (const float& min, const float& max)
18  {
19  return (static_cast<float> (GetNext ()) / RAND_MAX) * (max - min) + min;
20  }
21 
22  double RandomHelper::GetNext (const double& min, const double& max)
23  {
24  return (static_cast<double> (GetNext ()) / RAND_MAX) * (max - min) + min;
25  }
26 
28  {
29  return rand ();
30  }
31 
32  bool RandomHelper::Percentage (const float& percentage)
33  {
34  return (GetNext (0.f, 100.f) <= percentage) ? true : false;
35  }
36 
37 } // namespace yap