GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/util/random.h Lines: 3 3 100.0 %
Date: 2021-03-22 Branches: 2 2 100.0 %

Line Exec Source
1
/*********************                                                        */
2
/*! \file random.h
3
 ** \verbatim
4
 ** Top contributors (to current version):
5
 **   Aina Niemetz, Andres Noetzli, Mathias Preiner
6
 ** This file is part of the CVC4 project.
7
 ** Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 ** in the top-level source directory and their institutional affiliations.
9
 ** All rights reserved.  See the file COPYING in the top-level source
10
 ** directory for licensing information.\endverbatim
11
 **
12
 ** \brief A Random Number Generator.
13
 **
14
 ** A random number generator, implements the xorshift* generator
15
 ** (see S. Vigna, An experimental exploration of Marsaglia's xorshift
16
 ** generators, scrambled. ACM Trans. Math. Softw. 42(4): 30:1-30:23, 2016).
17
 **/
18
19
#include "cvc4_private.h"
20
21
#ifndef CVC4__UTIL__RANDOM_H
22
#define CVC4__UTIL__RANDOM_H
23
24
namespace CVC4 {
25
26
class Random
27
{
28
 public:
29
  using result_type = uint64_t;
30
31
  /** Constructor. */
32
  Random(uint64_t seed);
33
34
  /** Get current RNG (singleton).  */
35
4937567
  static Random& getRandom()
36
  {
37
4937567
    static thread_local Random s_current(0);
38
4937567
    return s_current;
39
  }
40
41
  /** Get the minimum number that can be picked. */
42
  static constexpr uint64_t min() { return 0u; }
43
44
  /** Get the maximum number that can be picked. */
45
  static constexpr uint64_t max() { return UINT64_MAX; }
46
47
  /** Set seed of Random.  */
48
  void setSeed(uint64_t seed);
49
50
  /** Operator overload to pick random uin64_t number (see rand()). */
51
  uint64_t operator()();
52
53
  /** Next random uint64_t number. */
54
  uint64_t rand();
55
56
  /** Pick random uint64_t number between from and to (inclusive). */
57
  uint64_t pick(uint64_t from, uint64_t to);
58
59
  /** Pick random double number between from and to (inclusive). */
60
  double pickDouble(double from, double to);
61
62
  /** Pick with given probability (yes / no). */
63
  bool pickWithProb(double probability);
64
65
 private:
66
  /* The seed of the RNG. */
67
  uint64_t d_seed;
68
  /* The current state of the RNG. */
69
  uint64_t d_state;
70
};
71
72
}  // namespace CVC4
73
#endif