tesseract  4.0.0-1-g2a2b
tesseract::TRand Class Reference

#include <helpers.h>

Public Member Functions

 TRand ()
 
void set_seed (uint64_t seed)
 
void set_seed (const std::string &str)
 
int32_t IntRand ()
 
double SignedRand (double range)
 
double UnsignedRand (double range)
 

Detailed Description

Definition at line 42 of file helpers.h.

Constructor & Destructor Documentation

◆ TRand()

tesseract::TRand::TRand ( )
inline

Definition at line 44 of file helpers.h.

44 : seed_(1) {}

Member Function Documentation

◆ IntRand()

int32_t tesseract::TRand::IntRand ( )
inline

Definition at line 56 of file helpers.h.

56  {
57  Iterate();
58  return seed_ >> 33;
59  }

◆ set_seed() [1/2]

void tesseract::TRand::set_seed ( uint64_t  seed)
inline

Definition at line 46 of file helpers.h.

46  {
47  seed_ = seed;
48  }

◆ set_seed() [2/2]

void tesseract::TRand::set_seed ( const std::string &  str)
inline

Definition at line 50 of file helpers.h.

50  {
51  std::hash<std::string> hasher;
52  set_seed(static_cast<uint64_t>(hasher(str)));
53  }
void set_seed(uint64_t seed)
Definition: helpers.h:46

◆ SignedRand()

double tesseract::TRand::SignedRand ( double  range)
inline

Definition at line 61 of file helpers.h.

61  {
62  return range * 2.0 * IntRand() / INT32_MAX - range;
63  }
int32_t IntRand()
Definition: helpers.h:56

◆ UnsignedRand()

double tesseract::TRand::UnsignedRand ( double  range)
inline

Definition at line 65 of file helpers.h.

65  {
66  return range * IntRand() / INT32_MAX;
67  }
int32_t IntRand()
Definition: helpers.h:56

The documentation for this class was generated from the following file: