Cleaning poker code pt 1.

This commit is contained in:
2024-09-08 23:12:03 -05:00
parent b4e261d954
commit d5b3b6d619
11 changed files with 214 additions and 120 deletions

View File

@ -6,4 +6,5 @@
target_sources(${DAWN_TARGET_NAME}
PRIVATE
String.cpp
Random.cpp
)

16
src/dawn/util/Random.cpp Normal file
View File

@ -0,0 +1,16 @@
// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "Random.hpp"
using namespace Dawn;
void Random::seed(const uint64_t seed) {
srand(seed);
}
uint64_t Random::next() {
return rand();
}

49
src/dawn/util/Random.hpp Normal file
View File

@ -0,0 +1,49 @@
// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
namespace Dawn {
class Random final {
public:
/**
* Seeds the random number generator with the provided seed.
*
* @param seed Seed to use for the random number generator.
*/
static void seed(const uint64_t seed);
/**
* Returns the next random number from the generator.
*
* @return The next random number.
*/
static uint64_t next();
/**
* Returns a random number between the provided min and max values.
*
* @param min Minimum value for the random number.
* @param max Maximum value for the random number.
* @return Random number between min and max.
*/
static float_t random(float_t min, float_t max) {
return min + (float_t)next() / (float_t)RAND_MAX * (max - min);
}
/**
* Returns a random number between the provided min and max values.
*
* @param min Minimum value for the random number.
* @param max Maximum value for the random number.
* @return Random number between min and max.
*/
template<typename T>
static T random(T min, T max) {
return (T)(min + (next() % (max - min + 1)));
}
};
}