Moved a tonne of code around
This commit is contained in:
56
src/dawn/util/rand.h
Normal file
56
src/dawn/util/rand.h
Normal file
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "math.h"
|
||||
|
||||
/**
|
||||
* Seed the random number generator
|
||||
* @param seed Seed to use for the seeded random number generator.
|
||||
*/
|
||||
#define randSeed(seed) (srand(seed))
|
||||
|
||||
/**
|
||||
* Generates a random int32_t.
|
||||
* @returns A random int32_t number.
|
||||
*/
|
||||
#define randInt32() ((int32_t)rand())
|
||||
|
||||
/**
|
||||
* Generates a random floating point number.
|
||||
* @returns A random floating point number.
|
||||
*/
|
||||
#define randFloat() (((float)randInt32()) * MATH_PI)
|
||||
|
||||
/**
|
||||
* Generates a random uint32_t
|
||||
* @returns A random uint32_t number.
|
||||
*/
|
||||
#define randUint32() (uint32_t)randInt32()
|
||||
|
||||
/**
|
||||
* Generates a random uint8_t
|
||||
* @returns A random uint8_t number.
|
||||
*/
|
||||
#define randUint8() (uint8_t)randInt32()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Clamps a random number generation.
|
||||
* @param n Number that has been generated from the random.
|
||||
* @param min Minimum value to generate from. (Inclusive)
|
||||
* @param max Maximum value to generate to. (Exclusive)
|
||||
* @return Random number between min and max.
|
||||
*/
|
||||
#define randRange(n, min, max) (mathMod(n, (max-min)) + min)
|
||||
|
||||
#define randInt32Range(min, max) randRange(randInt32(), min, max)
|
||||
#define randFloatRange(min, max) ((float)fmod(randFloat(), max- min) + min)
|
||||
#define randUint32Range(min, max) randRange(randUint32(), min, max)
|
||||
#define randUint8Range(min, max) randRange(randUint8(), min, max)
|
Reference in New Issue
Block a user