diff options
| -rw-r--r-- | game/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | game/Random.cpp | 28 | ||||
| -rw-r--r-- | game/Random.h | 11 | 
3 files changed, 40 insertions, 1 deletions
| diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 208132c..60e4d08 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -4,7 +4,6 @@ set(CMAKE_C_STANDARD 11)  set(CMAKE_CXX_STANDARD 20)  set(CMAKE_EXPORT_COMPILE_COMMANDS 1)  set(CMAKE_BUILD_TYPE Debug) -  project(game C CXX)  add_subdirectory(../src crepe) @@ -58,6 +57,7 @@ add_executable(main  	hud/HudSubScene.cpp  	hud/HudScript.cpp  	hud/SpeedScript.cpp +	Random.cpp  )  target_link_libraries(main PUBLIC crepe) diff --git a/game/Random.cpp b/game/Random.cpp new file mode 100644 index 0000000..59be3c5 --- /dev/null +++ b/game/Random.cpp @@ -0,0 +1,28 @@ +#include <cstdlib> + +#include "Random.h" + +float Random::f(float upper, float lower) { +	float range = upper - lower; +	float x = ((float) rand() / (float) (RAND_MAX)) * range; +	return x + lower; +} + +double Random::d(double upper, double lower) { +	double range = upper - lower; +	double x = ((double) rand() / (double) (RAND_MAX)) * range; +	return x + lower; +} + +int Random::i(int upper, int lower) { +	int range = upper - lower; +	int x = rand() % range; +	return x + lower; +} + +unsigned Random::u(unsigned upper, unsigned lower) { +	unsigned range = upper - lower; +	unsigned x = rand() % range; +	return x + lower; +} + diff --git a/game/Random.h b/game/Random.h new file mode 100644 index 0000000..cf05e87 --- /dev/null +++ b/game/Random.h @@ -0,0 +1,11 @@ +#pragma once + +class Random { +public: +	static float f(float upper = 1.0, float lower = 0.0); +	static double d(double upper = 1.0, double lower = 0.0); +	static int i(int upper, int lower = 0); +	static unsigned u(unsigned upper, unsigned lower = 0); + +}; + |