STE-Industries: utilities testing
RandomGenerator.inl
Go to the documentation of this file.
1 
14 namespace GraphicSpace
15 {
16 
28 
29 inline RandomGenerator::RandomGenerator(void) noexcept:
30  Selector(229, 17, 0x10000),
31  Generator
32  {
33  SimpleRandomGenerator(65535 + 1, 293, 4294836225),
34  SimpleRandomGenerator(32767 * 4 + 1, 283, 4294705156),
35  SimpleRandomGenerator(923 + 1, 37, 4294574089),
36  SimpleRandomGenerator(65531 + 1, 281, 4294311961),
37  SimpleRandomGenerator(65521 + 1, 277, 4293001441),
38  SimpleRandomGenerator(65519 + 1, 271, 4292739361),
39  SimpleRandomGenerator(65509 + 1, 269, 4291429081),
40  SimpleRandomGenerator(65497 + 1, 269, 4289857009),
41  SimpleRandomGenerator(65491 + 1, 257, 4289071081),
42  SimpleRandomGenerator(65489 + 1, 251, 4288809121),
43  SimpleRandomGenerator(65483 + 1, 241, 4288023289),
44  SimpleRandomGenerator(65479 + 1, 239, 4287499441),
45  SimpleRandomGenerator(65477 + 1, 233, 4287237529),
46  SimpleRandomGenerator(65473 + 1, 229, 4286713729),
47  SimpleRandomGenerator(65459 + 1, 227, 4284880681),
48  SimpleRandomGenerator(65453 + 1, 223, 4284095209),
49  SimpleRandomGenerator(65449 + 1, 211, 4283571601),
50  SimpleRandomGenerator(65447 + 1, 199, 4283309809),
51  SimpleRandomGenerator(65437 + 1, 197, 4282000969),
52  SimpleRandomGenerator(65431 + 1, 193, 4281215761),
53  SimpleRandomGenerator(65423 + 1, 191, 4280168929),
54  SimpleRandomGenerator(65419 + 1, 181, 4280168929),
55  SimpleRandomGenerator(65413 + 1, 179, 4278860569),
56  SimpleRandomGenerator(65411 + 1, 173, 4278598921),
57  SimpleRandomGenerator(65407 + 1, 167, 4278075649),
58  SimpleRandomGenerator(65393 + 1, 163, 4276244449),
59  SimpleRandomGenerator(65389 + 1, 157, 4275721321),
60  SimpleRandomGenerator(65381 + 1, 151, 4274675161),
61  SimpleRandomGenerator(65371 + 1, 149, 4273367641)
62  }
63  {
64  }
65 
79 
80 inline void RandomGenerator::SetSeed(const uint_fast32_t Seed
81  [NUMBER_OF_GENERATORS + 1]) noexcept
82  {
83  register unsigned int Index;
84 
85  for (Index = 0; Index < NUMBER_OF_GENERATORS; ++Index)
86  Generator [Index].SetSeed(Seed [Index + 1]);
88  }
89 
103 
104 inline void RandomGenerator::GetSeed(uint_fast32_t Seed
105  [NUMBER_OF_GENERATORS + 1]) const noexcept
106  {
107  register unsigned int Index;
108 
109  for (Index = 0; Index < NUMBER_OF_GENERATORS; ++Index)
110  Seed [Index + 1] = Generator [Index].GetValue();
112  }
113 
127 
128 inline void RandomGenerator::ModifySeed(uint_fast32_t Value) noexcept
129  {
130  register unsigned int Index;
131 
132  for (Index = 0; Index < NUMBER_OF_GENERATORS; ++Index)
133  Generator [Index].SetSeed(Generator [Index].GetValue() ^ Value);
134  Selector.SetSeed(Selector.GetValue() ^ Value);
135  }
136 
159 
160 inline uint_fast32_t RandomGenerator::Generate(uint_fast32_t Maximum)
161  noexcept
162  {
163  return Generator [Selector.Generate(NUMBER_OF_GENERATORS - 1)].
164  Generate(Maximum);
165  }
166 
194 
195 inline unsigned int RandomGenerator::Select(register const uint_fast32_t*
196  Probability, unsigned int Elements) noexcept
197  {
198  register uint_fast32_t Value;
199  register const uint_fast32_t* Pointer;
200 
201  Value = 0;
202  Pointer = Probability + Elements;
203  while (Probability < Pointer)
204  Value += *Probability++;
205  if (Value == 0)
206  return UINT_MAX;
207  Value = Generate(Value - 1);
208  Pointer = Probability -= Elements;
209  for (;;)
210  {
211  if (Value < *Probability)
212  return static_cast<unsigned int>(Probability - Pointer);
213  Value -= *Probability++;
214  }
215  }
216 
217 }
GraphicSpace::SimpleRandomGenerator::SetSeed
void SetSeed(uint_fast32_t thisConstant) noexcept
Definition: SimpleRandomGenerator.inl:100
GraphicSpace::RandomGenerator::NUMBER_OF_GENERATORS
static constexpr unsigned int NUMBER_OF_GENERATORS
Definition: RandomGenerator.h:37
GraphicSpace::SimpleRandomGenerator::GetValue
uint_fast32_t GetValue(void) const noexcept
Definition: SimpleRandomGenerator.inl:115
GraphicSpace::RandomGenerator::Select
unsigned int Select(register const uint_fast32_t *Probability, unsigned int Elements) noexcept
Definition: RandomGenerator.inl:195
GraphicSpace::SimpleRandomGenerator
Definition: SimpleRandomGenerator.h:31
GraphicSpace::RandomGenerator::Selector
SimpleRandomGenerator Selector
Definition: RandomGenerator.h:50
GraphicSpace::RandomGenerator::Generate
uint_fast32_t Generate(uint_fast32_t Maximum) noexcept
Definition: RandomGenerator.inl:160
GraphicSpace::RandomGenerator::RandomGenerator
RandomGenerator(void) noexcept
Definition: RandomGenerator.inl:29
GraphicSpace::RandomGenerator::GetSeed
void GetSeed(uint_fast32_t Seed[NUMBER_OF_GENERATORS+1]) const noexcept
Definition: RandomGenerator.inl:104
GraphicSpace::RandomGenerator::ModifySeed
void ModifySeed(uint_fast32_t Value) noexcept
Definition: RandomGenerator.inl:128
GraphicSpace
Definition: Bitmap.cpp:29
GraphicSpace::RandomGenerator::Generator
SimpleRandomGenerator Generator[NUMBER_OF_GENERATORS]
Definition: RandomGenerator.h:55
GraphicSpace::RandomGenerator::SetSeed
void SetSeed(const uint_fast32_t Seed[NUMBER_OF_GENERATORS+1]) noexcept
Definition: RandomGenerator.inl:80