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

Side by Side Diff: base/rand_util.h

Issue 10525003: Update comments in rand_util.h. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 6 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 9 #include <string>
10 10
11 #include "base/base_export.h" 11 #include "base/base_export.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 13
14 namespace base { 14 namespace base {
15 15
16 // Returns a random number in range [0, kuint64max]. Thread-safe. 16 // The random number generator functions below generate
17 // cryptographically secure random numbers. They are thread-safe.
18
19 // Random integer in range [0, kuint64max].
17 BASE_EXPORT uint64 RandUint64(); 20 BASE_EXPORT uint64 RandUint64();
18 21
19 // Returns a random number between min and max (inclusive). Thread-safe. 22 // Random integer in range [min, max).
20 BASE_EXPORT int RandInt(int min, int max); 23 BASE_EXPORT int RandInt(int min, int max);
21 24
22 // Returns a random number in range [0, range). Thread-safe. 25 // Random integer in range [0, range).
23 // 26 //
24 // Note that this can be used as an adapter for std::random_shuffle(): 27 // Note that this can be used as an adapter for std::random_shuffle():
25 // Given a pre-populated |std::vector<int> myvector|, shuffle it as 28 // Given a pre-populated |std::vector<int> myvector|, shuffle it as
26 // std::random_shuffle(myvector.begin(), myvector.end(), base::RandGenerator); 29 // std::random_shuffle(myvector.begin(), myvector.end(), base::RandGenerator);
27 BASE_EXPORT uint64 RandGenerator(uint64 range); 30 BASE_EXPORT uint64 RandGenerator(uint64 range);
28 31
29 // Returns a random double in range [0, 1). Thread-safe. 32 // Random double in range [0, 1).
Ryan Sleevi 2012/06/04 17:46:30 I feel like these comments were correct as origina
30 BASE_EXPORT double RandDouble(); 33 BASE_EXPORT double RandDouble();
31 34
32 // Given input |bits|, convert with maximum precision to a double in 35 // Given input |bits|, convert with maximum precision to a double in
33 // the range [0, 1). Thread-safe. 36 // the range [0, 1). Thread-safe.
34 BASE_EXPORT double BitsToOpenEndedUnitInterval(uint64 bits); 37 BASE_EXPORT double BitsToOpenEndedUnitInterval(uint64 bits);
35 38
36 // Fills |output_length| bytes of |output| with cryptographically strong random 39 // Fills |output_length| bytes of |output| with cryptographically strong random
37 // data. 40 // data.
38 BASE_EXPORT void RandBytes(void* output, size_t output_length); 41 BASE_EXPORT void RandBytes(void* output, size_t output_length);
39 42
40 // Fills a string of length |length| with with cryptographically strong random 43 // Fills a string of length |length| with with cryptographically strong random
41 // data and returns it. |length| should be nonzero. 44 // data and returns it. |length| should be nonzero.
42 // 45 //
43 // Note that this is a variation of |RandBytes| with a different return type. 46 // Note that this is a variation of |RandBytes| with a different return type.
44 BASE_EXPORT std::string RandBytesAsString(size_t length); 47 BASE_EXPORT std::string RandBytesAsString(size_t length);
45 48
46 #ifdef OS_POSIX 49 #ifdef OS_POSIX
47 BASE_EXPORT int GetUrandomFD(); 50 BASE_EXPORT int GetUrandomFD();
48 #endif 51 #endif
49 52
50 } // namespace base 53 } // namespace base
51 54
52 #endif // BASE_RAND_UTIL_H_ 55 #endif // BASE_RAND_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698