Simulant  21.12-574
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
random.h
1 #pragma once
2 
3 #include <random>
4 #include <vector>
5 #include "../types.h"
6 
7 #include <cstdint>
8 
9 #define RND_U32 uint32_t
10 #define RND_U64 uint64_t
11 
12 #include "_rnd.h"
13 
14 namespace smlt {
15 
17 public:
19  RandomGenerator(uint32_t seed);
20 
21  template<typename T>
22  T choice(T* array, std::size_t count) {
23  return array[int_in_range(0, count - 1)];
24  }
25 
26  template<typename T>
27  T choice(const std::vector<T>& choices) {
28  return this->choice<T>((T*) &choices[0], choices.size());
29  }
30 
31  template<typename T>
32  void shuffle(T* array, std::size_t count);
33 
34  template<typename T>
35  void shuffle(std::vector<T>& choices);
36 
37  template<typename T>
38  std::vector<T> shuffled(const std::vector<T>& choices);
39 
40  float float_in_range(float lower, float upper);
41  int32_t int_in_range(int32_t lower, int32_t upper);
42  smlt::Vec2 point_in_circle(float diameter);
43  smlt::Vec3 point_in_sphere(float diameter);
44  smlt::Vec2 point_on_circle(float diameter);
45  smlt::Vec3 point_on_sphere(float diameter);
46  smlt::Vec2 direction_2d();
47  smlt::Vec3 direction_3d();
48 
49 private:
50  rnd_pcg_t rand_;
51 };
52 
53 
54 }
smlt::RandomGenerator
Definition: random.h:16
smlt::Vec3
Definition: vec3.h:23
smlt
Definition: animation.cpp:25
rnd_pcg_t
Definition: _rnd.h:26
smlt::Vec2
Definition: vec2.h:14