Cogs.Core
Random.h
1#pragma once
2
3#include "Base.h"
4
5#include <cstdint>
6#include <random>
7
8
9namespace Cogs::Core
10{
11 class Context;
12
13 class COGSCORE_DLL_API Random
14 {
15 public:
16 Random(Context * /*context*/):
17 seq({ rd(), rd(), rd(), rd(), rd(), rd(), rd(), rd() }),
18 mt(0),
19 mt_seed(seq),
20 uniform_uint8(0, 255),
21 uniform_uint16(0, 65535),
22 uniform_uint32(0, 4294967295u),
23 uniform_float(0.0f, 1.0f),
24 uniform_double(0.0, 1.0),
25 uniform_float2(-1.0f, 1.0f),
26 uniform_double2(-1.0, 1.0)
27 { }
28 ~Random() {}
29
30 void Reset(std::mt19937::result_type seed)
31 {
32 mt = std::mt19937(seed);
33 uniform_uint8.reset();
34 uniform_uint16.reset();
35 uniform_uint32.reset();
36 uniform_float.reset();
37 uniform_double.reset();
38 uniform_float2.reset();
39 uniform_double2.reset();
40 }
41
42 std::random_device rd;
43 std::seed_seq seq;
44 std::mt19937 mt;
45 std::mt19937 mt_seed;
46
47 std::uniform_int_distribution<uint32_t> uniform_uint8;
48 std::uniform_int_distribution<uint32_t> uniform_uint16;
49 std::uniform_int_distribution<uint32_t> uniform_uint32;
50 std::uniform_real_distribution<float> uniform_float;
51 std::uniform_real_distribution<double> uniform_double;
52 std::uniform_real_distribution<float> uniform_float2;
53 std::uniform_real_distribution<double> uniform_double2;
54 };
55}
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
@ Reset
Input Focus lost event. Typically reset any cached mouse/keyboard state.