diff options
| author | Wboerenkamps <wrj.boerenkamps@student.avans.nl> | 2025-01-08 12:01:19 +0100 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-08 12:01:19 +0100 | 
| commit | 8055d401fc7c553a7036336b4b2fb2fca99a5986 (patch) | |
| tree | 30d111450c8862c59371b1756645967fdeae79bf | |
| parent | ad5fb53986fcc3f3b3c5369574e0f8e95051f3d9 (diff) | |
| parent | 9e54f238fbfced9243cc544c1461f21eefd5b0f1 (diff) | |
Merge pull request #108 from lonkaars/loek/random
add Random.h
| -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 661e2bc..c8fa989 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) @@ -48,6 +47,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); + +}; + |