security/sandbox/chromium/base/rand_util.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/sandbox/chromium/base/rand_util.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,58 @@
     1.4 +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#ifndef BASE_RAND_UTIL_H_
     1.9 +#define BASE_RAND_UTIL_H_
    1.10 +
    1.11 +#include <string>
    1.12 +
    1.13 +#include "base/base_export.h"
    1.14 +#include "base/basictypes.h"
    1.15 +
    1.16 +namespace base {
    1.17 +
    1.18 +// Returns a random number in range [0, kuint64max]. Thread-safe.
    1.19 +BASE_EXPORT uint64 RandUint64();
    1.20 +
    1.21 +// Returns a random number between min and max (inclusive). Thread-safe.
    1.22 +BASE_EXPORT int RandInt(int min, int max);
    1.23 +
    1.24 +// Returns a random number in range [0, range).  Thread-safe.
    1.25 +//
    1.26 +// Note that this can be used as an adapter for std::random_shuffle():
    1.27 +// Given a pre-populated |std::vector<int> myvector|, shuffle it as
    1.28 +//   std::random_shuffle(myvector.begin(), myvector.end(), base::RandGenerator);
    1.29 +BASE_EXPORT uint64 RandGenerator(uint64 range);
    1.30 +
    1.31 +// Returns a random double in range [0, 1). Thread-safe.
    1.32 +BASE_EXPORT double RandDouble();
    1.33 +
    1.34 +// Given input |bits|, convert with maximum precision to a double in
    1.35 +// the range [0, 1). Thread-safe.
    1.36 +BASE_EXPORT double BitsToOpenEndedUnitInterval(uint64 bits);
    1.37 +
    1.38 +// Fills |output_length| bytes of |output| with random data.
    1.39 +//
    1.40 +// WARNING:
    1.41 +// Do not use for security-sensitive purposes.
    1.42 +// See crypto/ for cryptographically secure random number generation APIs.
    1.43 +BASE_EXPORT void RandBytes(void* output, size_t output_length);
    1.44 +
    1.45 +// Fills a string of length |length| with with random data and returns it.
    1.46 +// |length| should be nonzero.
    1.47 +//
    1.48 +// Note that this is a variation of |RandBytes| with a different return type.
    1.49 +//
    1.50 +// WARNING:
    1.51 +// Do not use for security-sensitive purposes.
    1.52 +// See crypto/ for cryptographically secure random number generation APIs.
    1.53 +BASE_EXPORT std::string RandBytesAsString(size_t length);
    1.54 +
    1.55 +#if defined(OS_POSIX)
    1.56 +BASE_EXPORT int GetUrandomFD();
    1.57 +#endif
    1.58 +
    1.59 +}  // namespace base
    1.60 +
    1.61 +#endif  // BASE_RAND_UTIL_H_

mercurial