Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(974)

Side by Side Diff: webrtc/rtc_base/random.h

Issue 2966523003: Reland "Update includes for webrtc/{base => rtc_base} rename (3/3)" (Closed)
Patch Set: Restoring prime suspect includes Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/rtc_base/race_checker.cc ('k') | webrtc/rtc_base/random.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_RTC_BASE_RANDOM_H_ 11 #ifndef WEBRTC_RTC_BASE_RANDOM_H_
12 #define WEBRTC_RTC_BASE_RANDOM_H_ 12 #define WEBRTC_RTC_BASE_RANDOM_H_
13 13
14 #include <limits> 14 #include <limits>
15 15
16 #include "webrtc/rtc_base/checks.h"
17 #include "webrtc/rtc_base/constructormagic.h"
16 #include "webrtc/typedefs.h" 18 #include "webrtc/typedefs.h"
17 #include "webrtc/base/constructormagic.h"
18 #include "webrtc/base/checks.h"
19 19
20 namespace webrtc { 20 namespace webrtc {
21 21
22 class Random { 22 class Random {
23 public: 23 public:
24 // TODO(tommi): Change this so that the seed can be initialized internally, 24 // TODO(tommi): Change this so that the seed can be initialized internally,
25 // e.g. by offering two ways of constructing or offer a static method that 25 // e.g. by offering two ways of constructing or offer a static method that
26 // returns a seed that's suitable for initialization. 26 // returns a seed that's suitable for initialization.
27 // The problem now is that callers are calling clock_->TimeInMicroseconds() 27 // The problem now is that callers are calling clock_->TimeInMicroseconds()
28 // which calls TickTime::Now().Ticks(), which can return a very low value on 28 // which calls TickTime::Now().Ticks(), which can return a very low value on
29 // Mac and can result in a seed of 0 after conversion to microseconds. 29 // Mac and can result in a seed of 0 after conversion to microseconds.
30 // Besides the quality of the random seed being poor, this also requires 30 // Besides the quality of the random seed being poor, this also requires
31 // the client to take on extra dependencies to generate a seed. 31 // the client to take on extra dependencies to generate a seed.
32 // If we go for a static seed generator in Random, we can use something from 32 // If we go for a static seed generator in Random, we can use something from
33 // webrtc/base and make sure that it works the same way across platforms. 33 // webrtc/rtc_base and make sure that it works the same way across platforms.
34 // See also discussion here: https://codereview.webrtc.org/1623543002/ 34 // See also discussion here: https://codereview.webrtc.org/1623543002/
35 explicit Random(uint64_t seed); 35 explicit Random(uint64_t seed);
36 36
37 // Return pseudo-random integer of the specified type. 37 // Return pseudo-random integer of the specified type.
38 // We need to limit the size to 32 bits to keep the output close to uniform. 38 // We need to limit the size to 32 bits to keep the output close to uniform.
39 template <typename T> 39 template <typename T>
40 T Rand() { 40 T Rand() {
41 static_assert(std::numeric_limits<T>::is_integer && 41 static_assert(std::numeric_limits<T>::is_integer &&
42 std::numeric_limits<T>::radix == 2 && 42 std::numeric_limits<T>::radix == 2 &&
43 std::numeric_limits<T>::digits <= 32, 43 std::numeric_limits<T>::digits <= 32,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 template <> 84 template <>
85 double Random::Rand<double>(); 85 double Random::Rand<double>();
86 86
87 // Return pseudo-random boolean value. 87 // Return pseudo-random boolean value.
88 template <> 88 template <>
89 bool Random::Rand<bool>(); 89 bool Random::Rand<bool>();
90 90
91 } // namespace webrtc 91 } // namespace webrtc
92 92
93 #endif // WEBRTC_RTC_BASE_RANDOM_H_ 93 #endif // WEBRTC_RTC_BASE_RANDOM_H_
OLDNEW
« no previous file with comments | « webrtc/rtc_base/race_checker.cc ('k') | webrtc/rtc_base/random.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698