59 lines
1.6 KiB
C++
59 lines
1.6 KiB
C++
// 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 0 and RAND_MAX.
|
|
*
|
|
* @return Random number between 0 and RAND_MAX.
|
|
*/
|
|
template<typename T>
|
|
static T random() {
|
|
return (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)));
|
|
}
|
|
};
|
|
} |