GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: unittest/random_generator.hpp Lines: 8 8 100.0 %
Date: 2024-02-13 11:12:33 Branches: 8 16 50.0 %

Line Branch Exec Source
1
///////////////////////////////////////////////////////////////////////////////
2
// BSD 3-Clause License
3
//
4
// Copyright (C) 2019-2021, LAAS-CNRS, University of Edinburgh
5
// Copyright note valid unless otherwise stated in individual files.
6
// All rights reserved.
7
///////////////////////////////////////////////////////////////////////////////
8
9
#ifndef CROCODDYL_RANDOM_GENERATOR_HPP_
10
#define CROCODDYL_RANDOM_GENERATOR_HPP_
11
12
#include <functional>
13
#include <random>
14
15
static std::mt19937 rng;
16
17
namespace crocoddyl {
18
namespace unittest {
19
20
template <typename IntType>
21
13
IntType random_int_in_range(IntType first = 0, IntType last = 10) {
22
13
  return std::uniform_int_distribution<IntType>(first, last)(rng);
23
}
24
25
template <typename RealType>
26
44
RealType random_real_in_range(RealType first = 0, RealType last = 1) {
27
44
  return std::uniform_real_distribution<RealType>(first, last)(rng);
28
}
29
30
4448
bool random_boolean() {
31
12
  static auto generator = std::bind(std::uniform_int_distribution<>(0, 1),
32


4460
                                    std::default_random_engine());
33
4448
  return generator();
34
}
35
36
}  // namespace unittest
37
}  // namespace crocoddyl
38
39
#endif  // CROCODDYL_RANDOM_GENERATOR_HPP_