Nebula
Loading...
Searching...
No Matches
randomnumbertable.h
Go to the documentation of this file.
1#pragma once
2#ifndef UTIL_RANDOMNUMBERTABLE_H
3#define UTIL_RANDOMNUMNERTABLE_H
4//------------------------------------------------------------------------------
15#include "core/types.h"
16
17//------------------------------------------------------------------------------
18namespace Util
19{
21{
22public:
24 static float Rand(IndexT key);
26 static float Rand(IndexT key, float minVal, float maxVal);
27
28private:
29 static const SizeT tableSize = 2048;
30 static const float randTable[tableSize];
31};
32
33//------------------------------------------------------------------------------
36inline float
38{
39 return randTable[key % tableSize];
40}
41
42//------------------------------------------------------------------------------
45inline float
46RandomNumberTable::Rand(IndexT key, float minVal, float maxVal)
47{
48 return minVal + (randTable[key % tableSize] * (maxVal - minVal));
49}
50
51} // namespace Util
52//------------------------------------------------------------------------------
53#endif
A table-based random-number generator.
Definition randomnumbertable.h:21
static const SizeT tableSize
Definition randomnumbertable.h:29
static float Rand(IndexT key)
return a pseudo-random number between 0 and 1
Definition randomnumbertable.h:37
static const float randTable[tableSize]
Definition randomnumbertable.h:30
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48