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

Side by Side Diff: base/rand_util.h

Issue 6883102: Add one-time randomization support for FieldTrial, and the ability to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Unit test cancel support. Created 9 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_RAND_UTIL_H_ 5 #ifndef BASE_RAND_UTIL_H_
6 #define BASE_RAND_UTIL_H_ 6 #define BASE_RAND_UTIL_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/base_api.h" 9 #include "base/base_api.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 11
12 namespace base { 12 namespace base {
13 13
14 // Returns a random number in range [0, kuint64max]. Thread-safe. 14 // Returns a random number in range [0, kuint64max]. Thread-safe.
15 BASE_API uint64 RandUint64(); 15 BASE_API uint64 RandUint64();
16 16
17 // Returns a random number between min and max (inclusive). Thread-safe. 17 // Returns a random number between min and max (inclusive). Thread-safe.
18 BASE_API int RandInt(int min, int max); 18 BASE_API int RandInt(int min, int max);
19 19
20 // Returns a random number in range [0, max). Thread-safe. 20 // Returns a random number in range [0, max). Thread-safe.
21 // 21 //
22 // Note that this can be used as an adapter for std::random_shuffle(): 22 // Note that this can be used as an adapter for std::random_shuffle():
23 // Given a pre-populated |std::vector<int> myvector|, shuffle it as 23 // Given a pre-populated |std::vector<int> myvector|, shuffle it as
24 // std::random_shuffle(myvector.begin(), myvector.end(), base::RandGenerator); 24 // std::random_shuffle(myvector.begin(), myvector.end(), base::RandGenerator);
25 BASE_API uint64 RandGenerator(uint64 max); 25 BASE_API uint64 RandGenerator(uint64 max);
26 26
27 // Returns a random double in range [0, 1). Thread-safe. 27 // Returns a random double in range [0, 1). Thread-safe.
28 BASE_API double RandDouble(); 28 BASE_API double RandDouble();
29 29
30 // Given input |bits|, convert with maximum precision to a rand-like
31 // double, i.e. in the range [0, 1). Thread-safe.
32 BASE_API double BitsToRandLikeDouble(uint64 bits);
33
30 } // namespace base 34 } // namespace base
31 35
32 #endif // BASE_RAND_UTIL_H_ 36 #endif // BASE_RAND_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698