CARLA
Random.h
Go to the documentation of this file.
1 // Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include <carla/geom/Location.h>
10 
11 #include <algorithm>
12 #include <random>
13 
14 namespace util {
15 
16  class Random {
17  public:
18 
19  static double Uniform(double min, double max) {
20  std::uniform_real_distribution<double> distribution(min, max);
21  return distribution(_engine);
22  }
23 
24  static carla::geom::Location Location(float min, float max) {
25  std::uniform_real_distribution<float> distribution(min, max);
26  return {distribution(_engine), distribution(_engine), distribution(_engine)};
27  }
28 
29  template <typename RangeT>
30  static void Shuffle(RangeT &range) {
31  std::shuffle(std::begin(range), std::end(range), _engine);
32  }
33 
34  private:
35 
36  // Defined in test.cpp.
37  static thread_local std::mt19937_64 _engine;
38  };
39 
40 } // namespace util
static double Uniform(double min, double max)
Definition: Random.h:19
static thread_local std::mt19937_64 _engine
Definition: Random.h:37
static carla::geom::Location Location(float min, float max)
Definition: Random.h:24
double min(double v1, double v2)
Definition: Simplify.h:294
static void Shuffle(RangeT &range)
Definition: Random.h:30