hashRandomPair.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hashRandomPair.cc
Go to the documentation of this file.
1 /* hashRandom.cc
2 */
3 #include "osl/hash/hashRandomPair.h"
4 #include <boost/random/mersenne_twister.hpp>
5 #include <boost/random/uniform_smallint.hpp>
6 #include <boost/random/variate_generator.hpp>
7
8 std::pair<char,char>
9 osl::hash::HashRandomPair::table[osl::hash::HashRandomPair::Length];
10 bool osl::hash::HashRandomPair::is_initialized = 0;
11
12 void osl::hash::HashRandomPair::setUp(unsigned int seed, unsigned int prob100)
13 {
14 boost::mt19937 mt19937(seed);
15 boost::uniform_smallint<> uniform100(0, 99);
16 boost::variate_generator<boost::mt19937, boost::uniform_smallint<> >
17 random100(mt19937, uniform100);
18
19 for (size_t i=0; i<Length; ++i) {
20 const unsigned int u = random100();
21 if (u < prob100)
22 table[i] = std::make_pair(1,0);
23 else if (u < prob100*2)
24 table[i] = std::make_pair(0,1);
25 else
26 table[i] = std::make_pair(0,0);
27 }
28 is_initialized = 1;
29 }
30
31
32 // ;;; Local Variables:
33 // ;;; mode:c++
34 // ;;; c-basic-offset:2
35 // ;;; End: