Diana Software
QBlindTools.cc
Go to the documentation of this file.
1 #include "QBlindTools.hh"
2 #include "QDiana.hh"
3 #include <sstream>
4 #define Alphabet "qwertyuiopasdfghjklzxcvbnm0123456789"
5 
6 
7 QBlindTools::QBlindTools(const std::string& stSeed)
8  : fStringSeed(stSeed)
9 {
10 
11  if (fStringSeed.length()<5) {
13  std::stringstream msg;
14  msg<<"Your string seed \""<<stSeed<<"\" is shorter than 5 char";
15  err.SetDescription(msg.str());
16 
17  DianaThrow(err);
18  }
19  std::string::iterator result=fStringSeed.begin();
20  std::transform(fStringSeed.begin(),fStringSeed.end(),result,tolower);
22 }
23 
24 double QBlindTools::Uniform() const
25 {
26  return Uniform(fSeed);
27 }
28 
29 
30 int QBlindTools::Scramble(const std::string& word) const
31 {
32  const char* StringAlphabet = Alphabet;
33  int length= word.length();
34  int sum = 0;
35  for (int i=0; i<length; i++){
36  for (int iAlphabet=0; iAlphabet<26+10; iAlphabet++){
37  if ( word[i] == StringAlphabet[iAlphabet] ){
38  sum= sum+ iAlphabet ;
39  }
40  }
41  }
42  return sum;
43 }
44 
45 double QBlindTools::Uniform(const int seed) const
46 {
47  if (seed<1 || seed>8000) {
49  std::stringstream msg;
50  msg<<"Your numeric seed \""<<seed<<"\" is out of the 1-8000 range";
51  err.SetDescription(msg.str());
52 
53  DianaThrow(err);
54  }
55 
56  int ia = 8121;
57  int ic = 28411;
58  int im = 134456;
59  unsigned int jRan = (seed*ia + ic) % im;
60 
61  jRan = (jRan*ia + ic) % im;
62  jRan = (jRan*ia + ic) % im;
63  jRan = (jRan*ia + ic) % im;
64 
65  double theRan = (float) jRan / (float) im;
66 
67  return theRan; //theRan is between 0.0 - 1.0
68 }
69 
err
Definition: CheckOF.C:114
#define Alphabet
Definition: QBlindTools.cc:4
#define DianaThrow(obj)
Definition: QDianaDebug.hh:26
@ QERR_OUT_OF_RANGE
Definition: QError.hh:28
QBlindTools(const std::string &stringSeed)
Definition: QBlindTools.cc:7
int Scramble(const std::string &word) const
Definition: QBlindTools.cc:30
std::string fStringSeed
Definition: QBlindTools.hh:26
double Uniform() const
clear members
Definition: QBlindTools.cc:24
error class with error type and description
Definition: QError.hh:115