forked from Hopson97/Minecraft-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "Random.h" | ||
|
||
|
||
namespace Random | ||
{ | ||
std::mt19937_64 randomEngine; | ||
|
||
void init() | ||
{ | ||
randomEngine.seed(std::time(nullptr)); | ||
} | ||
|
||
int64_t intInRange(int64_t low, int64_t high) | ||
{ | ||
std::uniform_int_distribution<int64_t> dist (low, high); | ||
return dist(randomEngine); | ||
} | ||
|
||
float floatInRange(float low, float high) | ||
{ | ||
std::uniform_real_distribution<float> dist (low, high); | ||
return dist(randomEngine); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#ifndef RANDOM_H_INCLUDED | ||
#define RANDOM_H_INCLUDED | ||
|
||
#include <random> | ||
#include <cstdint> | ||
#include <ctime> | ||
|
||
namespace Random | ||
{ | ||
void init(); | ||
|
||
int64_t intInRange(int64_t low, int64_t high); | ||
float floatInRange(float low, float high); | ||
|
||
template<typename Engine> | ||
class Generator | ||
{ | ||
public: | ||
Generator() | ||
{ | ||
m_randomEngine.seed(std::time(nullptr)); | ||
} | ||
|
||
int64_t intInRange(int64_t low, int64_t high) | ||
{ | ||
std::uniform_int_distribution<int64_t> dist (low, high); | ||
return dist(m_randomEngine); | ||
} | ||
|
||
float floatInRange(float low, float high) | ||
{ | ||
std::uniform_real_distribution<float> dist (low, high); | ||
return dist(m_randomEngine); | ||
} | ||
|
||
template<typename T> | ||
T numberInRange(T low, T high) | ||
{ | ||
std::uniform_real_distribution<T> dist (low, high); | ||
return dist(m_randomEngine); | ||
} | ||
|
||
private: | ||
Engine m_randomEngine; | ||
}; | ||
|
||
|
||
} | ||
|
||
#endif // RANDOM_H_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,28 @@ | ||
#include "Display.h" | ||
|
||
#include "Application.h" | ||
#include "Util/Random.h" | ||
|
||
#include <iostream> | ||
|
||
int main() | ||
{ | ||
Random::init(); | ||
|
||
Random::Generator<std::minstd_rand> randomGen; | ||
|
||
for (int i = 0; i < 10; i++) | ||
{ | ||
std::cout << randomGen.numberInRange(5.0, 8.0) << std::endl; | ||
} | ||
|
||
/* | ||
Display::init(); | ||
Application app; | ||
app.runMainGameLoop(); | ||
return 0; | ||
*/ | ||
} |