About to make the processing queue lock properly
This commit is contained in:
@@ -8,4 +8,5 @@ target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
memory.c
|
||||
string.c
|
||||
random.c
|
||||
)
|
||||
27
src/util/random.c
Normal file
27
src/util/random.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "random.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
void randomInit() {
|
||||
randomSeed(time(NULL));
|
||||
}
|
||||
|
||||
void randomSeed(const uint32_t seed) {
|
||||
srand(seed);
|
||||
}
|
||||
|
||||
int32_t randomI32(const int32_t min, const int32_t max) {
|
||||
assertTrue(min < max, "Min is not less than max");
|
||||
return (rand() % (max - min)) + min;
|
||||
}
|
||||
|
||||
float_t randomF32(const float_t min, const float_t max) {
|
||||
assertTrue(min < max, "Min is not less than max");
|
||||
return ((float_t)rand() / (float_t)RAND_MAX) * (max - min) + min;
|
||||
}
|
||||
43
src/util/random.h
Normal file
43
src/util/random.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
/**
|
||||
* Initializes the random number generator with a random seed.
|
||||
*
|
||||
* This function should be called once at the start of the program to
|
||||
* initialize the random number generator with a random seed. It uses
|
||||
* the current time to generate a seed.
|
||||
*/
|
||||
void randomInit();
|
||||
|
||||
/**
|
||||
* Sets the random seed for the random number generator.
|
||||
*
|
||||
* @param seed The seed to set.
|
||||
*/
|
||||
void randomSeed(const uint32_t seed);
|
||||
|
||||
/**
|
||||
* Generates a random integer between min and max.
|
||||
*
|
||||
* @param min The minimum value (inclusive).
|
||||
* @param max The maximum value (exclusive).
|
||||
* @return A random integer between min and max.
|
||||
*/
|
||||
int32_t randomI32(const int32_t min, const int32_t max);
|
||||
|
||||
/**
|
||||
* Generates a random float between min and max.
|
||||
*
|
||||
* @param min The minimum value (inclusive).
|
||||
* @param max The maximum value (exclusive).
|
||||
* @return A random float between min and max.
|
||||
*/
|
||||
float_t randomF32(const float_t min, const float_t max);
|
||||
Reference in New Issue
Block a user