UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
rand_pmms.h
Go to the documentation of this file.
1/*
2 * =====================================================================================
3 *
4 * Filename: rand_pmms.h
5 *
6 * Description:
7 *
8 * Version: 1.0
9 * Created: 05/31/2012 02:23:23 PM
10 * Revision: none
11 * Compiler: gcc
12 *
13 * Author: Milan Kabat (), kabat@ics.muni.cz
14 * Organization:
15 *
16 * =====================================================================================
17 */
18
19
20#include <cmath>
21#include <assert.h>
22
24{
25 public:
26 Rand_pmms() = default;
27
28 void seedi ( unsigned long int s )
29 {
30 assert(s > 0ul && s < 0x7FFFFFFFul);
31 seed = s;
32 val = s;
33 }
34
35 unsigned long int pmms_rand ( unsigned long int maxv )
36 {
37 unsigned long int raw_value = nextrand();
38
39 return (unsigned long) ((double)maxv * (double)raw_value / (double)0x7FFFFFFF);
40 }
41 private:
42
43 unsigned long int nextrand()
44 {
45 unsigned long long int const a = 16807ull;
46 unsigned long long int const m = 0x7FFFFFFFull;
47
48 val = (a * val) % m;
49
50 return val;
51 }
52
53 unsigned long int seed;
54 unsigned long int val;
55};
unsigned long int val
Definition rand_pmms.h:54
unsigned long int nextrand()
Definition rand_pmms.h:43
Rand_pmms()=default
unsigned long int seed
Definition rand_pmms.h:53
void seedi(unsigned long int s)
Definition rand_pmms.h:28
unsigned long int pmms_rand(unsigned long int maxv)
Definition rand_pmms.h:35