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

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Aina Niemetz, Andres Noetzli, Mathias Preiner
4
 *
5
 * This file is part of the cvc5 project.
6
 *
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.
11
 * ****************************************************************************
12
 *
13
 * A random number generator, implements the xorshift* generator
14
 * (see S. Vigna, An experimental exploration of Marsaglia's xorshift
15
 * generators, scrambled. ACM Trans. Math. Softw. 42(4): 30:1-30:23, 2016).
16
 */
17
18
#include "cvc5_private.h"
19
20
#ifndef CVC5__UTIL__RANDOM_H
21
#define CVC5__UTIL__RANDOM_H
22
23
namespace cvc5 {
24
25
class Random
26
{
27
 public:
28
  using result_type = uint64_t;
29
30
  /** Constructor. */
31
  Random(uint64_t seed);
32
33
  /** Get current RNG (singleton).  */
34
4402970
  static Random& getRandom()
35
  {
36
4402970
    static thread_local Random s_current(0);
37
4402970
    return s_current;
38
  }
39
40
  /** Get the minimum number that can be picked. */
41
  static constexpr uint64_t min() { return 0u; }
42
43
  /** Get the maximum number that can be picked. */
44
  static constexpr uint64_t max() { return UINT64_MAX; }
45
46
  /** Set seed of Random.  */
47
  void setSeed(uint64_t seed);
48
49
  /** Operator overload to pick random uin64_t number (see rand()). */
50
  uint64_t operator()();
51
52
  /** Next random uint64_t number. */
53
  uint64_t rand();
54
55
  /** Pick random uint64_t number between from and to (inclusive). */
56
  uint64_t pick(uint64_t from, uint64_t to);
57
58
  /** Pick random double number between from and to (inclusive). */
59
  double pickDouble(double from, double to);
60
61
  /** Pick with given probability (yes / no). */
62
  bool pickWithProb(double probability);
63
64
 private:
65
  /* The seed of the RNG. */
66
  uint64_t d_seed;
67
  /* The current state of the RNG. */
68
  uint64_t d_state;
69
};
70
71
}  // namespace cvc5
72
#endif