-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPreRandom.h
More file actions
60 lines (46 loc) · 1.14 KB
/
Copy pathPreRandom.h
File metadata and controls
60 lines (46 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* File: PreRandom.h
* Author: masoud
*
* Created on January 20, 2012, 5:37 AM
*/
#ifndef PRERANDOM_H
#define PRERANDOM_H
#include <iostream>
#include <fstream>
#include <limits>
#include <cstdint>
typedef uint32_t RandType;
class PreRandom {
public:
PreRandom();
PreRandom(short bits, unsigned int inbuf);
unsigned int openrandfile(const char *fname, int bits, int inbuf);
//RandType next();
inline RandType next() {
if (curpos == inbuffercount)
readnextchunk();
return buffer[curpos++];
}
//double unituniform();
inline double unituniform() {
RandType r = next();
return r / 4294967295.0;
}
virtual ~PreRandom();
private:
std::ifstream rndfile;
RandType* buffer; // should be change to template
unsigned int curpos;
unsigned int buffersize;
unsigned int inbuffercount;
unsigned int filepos;
//bool readnextchunk();
inline bool readnextchunk() {
std::cerr<<"reading another chunk..."<<std::endl;
curpos = 0;
rndfile.read((char*) buffer, buffersize);
return true;
}
};
#endif /* PRERANDOM_H */