[rAC, OSX] saveInChrome status now persistent.
[chromium-blink-merge.git] / base / rand_util.h
blobbae8c311782bc7374796c53e35887c6c1cc47ccc
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
3 // found in the LICENSE file.
5 #ifndef BASE_RAND_UTIL_H_
6 #define BASE_RAND_UTIL_H_
8 #include <string>
10 #include "base/base_export.h"
11 #include "base/basictypes.h"
13 namespace base {
15 // Returns a random number in range [0, kuint64max]. Thread-safe.
16 BASE_EXPORT uint64 RandUint64();
18 // Returns a random number between min and max (inclusive). Thread-safe.
19 BASE_EXPORT int RandInt(int min, int max);
21 // Returns a random number in range [0, range). Thread-safe.
23 // Note that this can be used as an adapter for std::random_shuffle():
24 // Given a pre-populated |std::vector<int> myvector|, shuffle it as
25 // std::random_shuffle(myvector.begin(), myvector.end(), base::RandGenerator);
26 BASE_EXPORT uint64 RandGenerator(uint64 range);
28 // Returns a random double in range [0, 1). Thread-safe.
29 BASE_EXPORT double RandDouble();
31 // Given input |bits|, convert with maximum precision to a double in
32 // the range [0, 1). Thread-safe.
33 BASE_EXPORT double BitsToOpenEndedUnitInterval(uint64 bits);
35 // Fills |output_length| bytes of |output| with random data.
37 // WARNING:
38 // Do not use for security-sensitive purposes.
39 // See crypto/ for cryptographically secure random number generation APIs.
40 BASE_EXPORT void RandBytes(void* output, size_t output_length);
42 // Fills a string of length |length| with with random data and returns it.
43 // |length| should be nonzero.
45 // Note that this is a variation of |RandBytes| with a different return type.
47 // WARNING:
48 // Do not use for security-sensitive purposes.
49 // See crypto/ for cryptographically secure random number generation APIs.
50 BASE_EXPORT std::string RandBytesAsString(size_t length);
52 #if defined(OS_POSIX)
53 BASE_EXPORT int GetUrandomFD();
54 #endif
56 } // namespace base
58 #endif // BASE_RAND_UTIL_H_