KSquare Utilities
RandomNumGenerator.cpp
Go to the documentation of this file.
1 /* RandomNumGenerator.cpp -- Class that represents one Random Number Generator.
2  * Copyright (C) 1994-2014 Kurt Kramer & Daniel J. Garcia
3  * For conditions of distribution and use, see copyright notice in KKB.h
4  */
5 #include "FirstIncludes.h"
6 
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <iostream>
10 #include <vector>
11 
12 #include "MemoryDebug.h"
13 
14 
15 #include "KKBaseTypes.h"
16 
17 using namespace std;
18 using namespace KKB;
19 
20 
22 
23 using namespace KKB;
24 
26 {
27 #if defined(WIN32)
28  _lrand48_sequence = 0x1234ABCD330E;
29 #else
30  _lrand48_sequence = 0x1234ABCD330ELLU;
31 #endif
32 }
33 
34 
36 {
37  kkint64 seedMask = 65535;
38  _lrand48_sequence &= seedMask;
39  kkint64 upperBits = _seed;
40  upperBits <<= 16;
41  _lrand48_sequence |= upperBits;
42 }
43 
44 
46 {
47 }
48 
49 
50 const kkint64 RandomNumGenerator::c = 0xB;
51 #if defined(WIN32)
52 const kkint64 RandomNumGenerator::a = 0x5DEECE66D;
53 const kkint64 RandomNumGenerator::m = 281474976710656;
54 const kkint64 RandomNumGenerator::mask = 281474976710655;
55 #else
56 const kkint64 RandomNumGenerator::a = 0x5DEECE66DLLU;
57 const kkint64 RandomNumGenerator::m = 281474976710656LLU;
58 const kkint64 RandomNumGenerator::mask = 281474976710655LLU;
59 #endif
60 
61 
62 
64 {
65  _lrand48_sequence = ( ((a * _lrand48_sequence) & mask) + c ) % m;
66  return (long)(_lrand48_sequence >> 17);
67 }
__int64 kkint64
Definition: KKBaseTypes.h:90
KKTHread * KKTHreadPtr
Represents one single random number generator.