ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
CaDiCaL::Random Class Reference

#include <random.hpp>

Public Member Functions

 Random ()
 
 Random (uint64_t seed)
 
void operator= (uint64_t seed)
 
 Random (const Random &other)
 
void operator+= (uint64_t a)
 
uint64_t seed () const
 
uint64_t next ()
 
uint32_t generate ()
 
int generate_int ()
 
bool generate_bool ()
 
double generate_double ()
 
int pick_int (int l, int r)
 
int pick_log (int l, int r)
 
double pick_double (double l, double r)
 

Detailed Description

Definition at line 14 of file random.hpp.

Constructor & Destructor Documentation

◆ Random() [1/3]

CaDiCaL::Random::Random ( )

Definition at line 219 of file cadical_random.cpp.

219 : state (1) {
220 add (hash_machine_identifier ());
221 add (hash_network_addresses ());
222 add (hash_clock_cycles ());
223 add (hash_process ());
224 add (hash_time ());
225#ifdef DO_PRINT_HASH
226 printf ("c PRINT_HASH %32s = %020" PRIu64 "\n", "combined", state);
227 fflush (stdout);
228#endif
229}
Here is the caller graph for this function:

◆ Random() [2/3]

CaDiCaL::Random::Random ( uint64_t seed)
inline

Definition at line 29 of file random.hpp.

29: state (seed) {}
uint64_t seed() const
Definition random.hpp:34
Here is the call graph for this function:

◆ Random() [3/3]

CaDiCaL::Random::Random ( const Random & other)
inline

Definition at line 31 of file random.hpp.

31: state (other.seed ()) {}
Here is the call graph for this function:

Member Function Documentation

◆ generate()

uint32_t CaDiCaL::Random::generate ( )
inline

Definition at line 43 of file random.hpp.

43 {
44 next ();
45 return state >> 32;
46 }
uint64_t next()
Definition random.hpp:36
Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_bool()

bool CaDiCaL::Random::generate_bool ( )
inline

Definition at line 48 of file random.hpp.

48{ return generate () < 2147483648u; }
uint32_t generate()
Definition random.hpp:43
Here is the call graph for this function:

◆ generate_double()

double CaDiCaL::Random::generate_double ( )
inline

Definition at line 52 of file random.hpp.

52{ return generate () / 4294967295.0; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_int()

int CaDiCaL::Random::generate_int ( )
inline

Definition at line 47 of file random.hpp.

47{ return (int) generate (); }
Here is the call graph for this function:

◆ next()

uint64_t CaDiCaL::Random::next ( )
inline

Definition at line 36 of file random.hpp.

36 {
37 state *= 6364136223846793005ul;
38 state += 1442695040888963407ul;
39 CADICAL_assert (state);
40 return state;
41 }
#define CADICAL_assert(ignore)
Definition global.h:14
Here is the caller graph for this function:

◆ operator+=()

void CaDiCaL::Random::operator+= ( uint64_t a)
inline

Definition at line 33 of file random.hpp.

33{ add (a); }

◆ operator=()

void CaDiCaL::Random::operator= ( uint64_t seed)
inline

Definition at line 30 of file random.hpp.

30{ state = seed; }
Here is the call graph for this function:

◆ pick_double()

double CaDiCaL::Random::pick_double ( double l,
double r )
inline

Definition at line 90 of file random.hpp.

90 {
91 CADICAL_assert (l <= r);
92 double res = (r - l) * generate_double ();
93 res += l;
94 CADICAL_assert (l <= res);
95 CADICAL_assert (res <= r);
96 return res;
97 }
double generate_double()
Definition random.hpp:52
Here is the call graph for this function:

◆ pick_int()

int CaDiCaL::Random::pick_int ( int l,
int r )
inline

Definition at line 56 of file random.hpp.

56 {
57 CADICAL_assert (l <= r);
58 const unsigned delta = 1 + r - (unsigned) l;
59 unsigned tmp = generate (), scaled;
60 if (delta) {
61 const double fraction = tmp / 4294967296.0;
62 scaled = delta * fraction;
63 } else
64 scaled = tmp;
65 const int res = scaled + l;
66 CADICAL_assert (l <= res);
67 CADICAL_assert (res <= r);
68 return res;
69 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pick_log()

int CaDiCaL::Random::pick_log ( int l,
int r )
inline

Definition at line 71 of file random.hpp.

71 {
72 CADICAL_assert (l <= r);
73 const unsigned delta = 1 + r - (unsigned) l;
74 int log_delta = delta ? 0 : 32;
75 while (log_delta < 32 && (1u << log_delta) < delta)
76 log_delta++;
77 const int log_res = pick_int (0, log_delta);
78 unsigned tmp = generate ();
79 if (log_res < 32)
80 tmp &= (1u << log_res) - 1;
81 if (delta)
82 tmp %= delta;
83 const int res = l + tmp;
84 CADICAL_assert (l <= res), CADICAL_assert (res <= r);
85 return res;
86 }
int pick_int(int l, int r)
Definition random.hpp:56
Here is the call graph for this function:

◆ seed()

uint64_t CaDiCaL::Random::seed ( ) const
inline

Definition at line 34 of file random.hpp.

34{ return state; }
Here is the caller graph for this function:

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