Add base game
This commit is contained in:
11
random-utils/CMakeLists.txt
Normal file
11
random-utils/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
add_library(
|
||||
RandomUtils
|
||||
RandomUtils.hpp
|
||||
RandomUtils.cpp
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
RandomUtils
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
26
random-utils/RandomUtils.cpp
Normal file
26
random-utils/RandomUtils.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "RandomUtils.hpp"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
namespace RandomUtils
|
||||
{
|
||||
bool seeded = false;
|
||||
|
||||
void seed()
|
||||
{
|
||||
if (seeded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
srand(time(NULL));
|
||||
seeded = true;
|
||||
}
|
||||
|
||||
int rand(int min, int max)
|
||||
{
|
||||
seed();
|
||||
|
||||
return min + std::rand() % (max - min + 1);
|
||||
}
|
||||
}
|
14
random-utils/RandomUtils.hpp
Normal file
14
random-utils/RandomUtils.hpp
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef RANDOM_HPP
|
||||
#define RANDOM_HPP
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
namespace RandomUtils
|
||||
{
|
||||
/**
|
||||
* Generates a random number between min and max (inclusive).
|
||||
*/
|
||||
int rand(int min = 0, int max = RAND_MAX);
|
||||
}
|
||||
|
||||
#endif // RANDOM_HPP
|
Reference in New Issue
Block a user