Berkeley SfM
random_generator.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, The Regents of the University of California (Regents).
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following
14  * disclaimer in the documentation and/or other materials provided
15  * with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Please contact the author(s) of this library if you have any questions.
34  * Authors: Erik Nelson ( eanelson@eecs.berkeley.edu )
35  * David Fridovich-Keil ( dfk@eecs.berkeley.edu )
36  */
37 
38 #ifndef BSFM_MATH_RANDOM_GENERATOR_H
39 #define BSFM_MATH_RANDOM_GENERATOR_H
40 
41 #include <glog/logging.h>
42 #include <math.h>
43 #include <string.h>
44 #include <time.h>
45 #include <vector>
46 
47 #include "../util/disallow_copy_and_assign.h"
48 
49 namespace bsfm {
50 namespace math {
51 
53  public:
54  // Construct with "RandomGenerator(RandomGenerator::Seed())".
55  explicit RandomGenerator(unsigned long seed);
56 
57  // Creates a damn good seed.
58  static unsigned long Seed();
59 
60  // Generates a random integer in [0, RAND_MAX).
61  int Integer();
62 
63  // Generates a random integer in [0, 'max').
64  int IntegerUniform(int max);
65 
66  // Generates a random integer in ['min', 'max').
67  int IntegerUniform(int min, int max);
68 
69  // Generates 'count' random integers in [0, RAND_MAX).
70  void Integers(size_t count, std::vector<int> *integers);
71 
72  // Generates 'count' random integers between ['min', 'max').
73  void IntegersUniform(size_t count, int min, int max,
74  std::vector<int> *integers);
75 
76  // Generates a random double in [0, 1).
77  double Double();
78 
79  // Generates a random double in ['min' and 'max').
80  double DoubleUniform(double min, double max);
81 
82  // Samples a double from a Gaussian distribution with parameters 'mean'
83  // and 'stddev'.
84  double DoubleGaussian(double mean, double stddev);
85 
86  // Generates 'count' random doubles in [0, 1).
87  void Doubles(size_t count, std::vector<double>* doubles);
88 
89  // Generates 'count' random doubles between ['min', 'max').
90  void DoublesUniform(size_t count, double min, double max,
91  std::vector<double>* doubles);
92 
93  // Samples 'count' doubles from a Gaussian distribution with parameters
94  // 'mean' and 'stddev'.
95  void DoublesGaussian(size_t count, double mean, double stddev,
96  std::vector<double>* doubles);
97 
98  private:
100 
101 }; //\class RandomGenerator
102 
103 } //\namespace math
104 } //\namespace bsfm
105 
106 #endif
double DoubleGaussian(double mean, double stddev)
void Integers(size_t count, std::vector< int > *integers)
void Doubles(size_t count, std::vector< double > *doubles)
void DoublesGaussian(size_t count, double mean, double stddev, std::vector< double > *doubles)
Definition: camera.cpp:50
void IntegersUniform(size_t count, int min, int max, std::vector< int > *integers)
double DoubleUniform(double min, double max)
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
void DoublesUniform(size_t count, double min, double max, std::vector< double > *doubles)
static unsigned long Seed()
RandomGenerator(unsigned long seed)