security/sandbox/chromium/base/rand_util.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #ifndef BASE_RAND_UTIL_H_
michael@0 6 #define BASE_RAND_UTIL_H_
michael@0 7
michael@0 8 #include <string>
michael@0 9
michael@0 10 #include "base/base_export.h"
michael@0 11 #include "base/basictypes.h"
michael@0 12
michael@0 13 namespace base {
michael@0 14
michael@0 15 // Returns a random number in range [0, kuint64max]. Thread-safe.
michael@0 16 BASE_EXPORT uint64 RandUint64();
michael@0 17
michael@0 18 // Returns a random number between min and max (inclusive). Thread-safe.
michael@0 19 BASE_EXPORT int RandInt(int min, int max);
michael@0 20
michael@0 21 // Returns a random number in range [0, range). Thread-safe.
michael@0 22 //
michael@0 23 // Note that this can be used as an adapter for std::random_shuffle():
michael@0 24 // Given a pre-populated |std::vector<int> myvector|, shuffle it as
michael@0 25 // std::random_shuffle(myvector.begin(), myvector.end(), base::RandGenerator);
michael@0 26 BASE_EXPORT uint64 RandGenerator(uint64 range);
michael@0 27
michael@0 28 // Returns a random double in range [0, 1). Thread-safe.
michael@0 29 BASE_EXPORT double RandDouble();
michael@0 30
michael@0 31 // Given input |bits|, convert with maximum precision to a double in
michael@0 32 // the range [0, 1). Thread-safe.
michael@0 33 BASE_EXPORT double BitsToOpenEndedUnitInterval(uint64 bits);
michael@0 34
michael@0 35 // Fills |output_length| bytes of |output| with random data.
michael@0 36 //
michael@0 37 // WARNING:
michael@0 38 // Do not use for security-sensitive purposes.
michael@0 39 // See crypto/ for cryptographically secure random number generation APIs.
michael@0 40 BASE_EXPORT void RandBytes(void* output, size_t output_length);
michael@0 41
michael@0 42 // Fills a string of length |length| with with random data and returns it.
michael@0 43 // |length| should be nonzero.
michael@0 44 //
michael@0 45 // Note that this is a variation of |RandBytes| with a different return type.
michael@0 46 //
michael@0 47 // WARNING:
michael@0 48 // Do not use for security-sensitive purposes.
michael@0 49 // See crypto/ for cryptographically secure random number generation APIs.
michael@0 50 BASE_EXPORT std::string RandBytesAsString(size_t length);
michael@0 51
michael@0 52 #if defined(OS_POSIX)
michael@0 53 BASE_EXPORT int GetUrandomFD();
michael@0 54 #endif
michael@0 55
michael@0 56 } // namespace base
michael@0 57
michael@0 58 #endif // BASE_RAND_UTIL_H_

mercurial