OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/modules/remote_bitrate_estimator/test/random.h" | |
12 | |
13 #include <math.h> | |
14 | |
15 namespace webrtc { | |
16 | |
17 Random::Random(uint32_t seed) : a_(0x531FDB97 ^ seed), b_(0x6420ECA8 + seed) { | |
18 } | |
19 | |
20 float Random::Rand() { | |
21 const float kScale = 1.0f / 0xffffffff; | |
pbos-webrtc
2015/07/06 10:01:40
Is this a remotely good rand() function? If you kn
stefan-webrtc
2015/07/06 10:54:26
I don't know where it came from, sorry.
| |
22 float result = kScale * b_; | |
23 a_ ^= b_; | |
24 b_ += a_; | |
25 return result; | |
26 } | |
27 | |
28 int Random::Gaussian(int mean, int standard_deviation) { | |
29 // Creating a Normal distribution variable from two independent uniform | |
30 // variables based on the Box-Muller transform, which is defined on the | |
31 // interval (0, 1], hence the mask+add below. | |
32 const double kPi = 3.14159265358979323846; | |
33 const double kScale = 1.0 / 0x80000000ul; | |
34 double u1 = kScale * ((a_ & 0x7ffffffful) + 1); | |
35 double u2 = kScale * ((b_ & 0x7ffffffful) + 1); | |
36 a_ ^= b_; | |
37 b_ += a_; | |
38 return static_cast<int>( | |
39 mean + standard_deviation * sqrt(-2 * log(u1)) * cos(2 * kPi * u2)); | |
40 } | |
41 } // namespace webrtc | |
OLD | NEW |