isherman@chromium.org | 01eaa0b | 2010-08-31 06:07:05 +0900 | [diff] [blame^] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
mark@chromium.org | b93c054 | 2008-09-30 07:18:01 +0900 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_RAND_UTIL_H_ |
| 6 | #define BASE_RAND_UTIL_H_ |
thakis@chromium.org | 01d1452 | 2010-07-27 08:08:24 +0900 | [diff] [blame] | 7 | #pragma once |
mark@chromium.org | b93c054 | 2008-09-30 07:18:01 +0900 | [diff] [blame] | 8 | |
| 9 | #include "base/basictypes.h" |
| 10 | |
| 11 | namespace base { |
| 12 | |
| 13 | // Returns a random number in range [0, kuint64max]. Thread-safe. |
deanm@chromium.org | 48c40ce | 2008-11-15 08:28:29 +0900 | [diff] [blame] | 14 | uint64 RandUint64(); |
mark@chromium.org | b93c054 | 2008-09-30 07:18:01 +0900 | [diff] [blame] | 15 | |
| 16 | // Returns a random number between min and max (inclusive). Thread-safe. |
| 17 | int RandInt(int min, int max); |
| 18 | |
isherman@chromium.org | 01eaa0b | 2010-08-31 06:07:05 +0900 | [diff] [blame^] | 19 | // Returns a random number in range [0, max). Thread-safe. |
| 20 | // |
| 21 | // Note that this can be used as an adapter for std::random_shuffle(): |
| 22 | // Given a pre-populated |std::vector<int> myvector|, shuffle it as |
| 23 | // std::random_shuffle(myvector.begin(), myvector.end(), base::RandGenerator); |
| 24 | uint64 RandGenerator(uint64 max); |
| 25 | |
mark@chromium.org | b93c054 | 2008-09-30 07:18:01 +0900 | [diff] [blame] | 26 | // Returns a random double in range [0, 1). Thread-safe. |
| 27 | double RandDouble(); |
| 28 | |
| 29 | } // namespace base |
| 30 | |
erg@google.com | bf6ce9f | 2010-01-27 08:08:02 +0900 | [diff] [blame] | 31 | #endif // BASE_RAND_UTIL_H_ |