blob: a4ea479e334edad7d181e5b4e27da46744deed11 [file] [log] [blame]
Kristian Monsenddb351d2011-06-28 21:49:31 +01001// Copyright (c) 2011 The Chromium Authors. All rights reserved.
Patrick Scottc7f5f852010-02-04 10:37:17 -05002// 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_
Iain Merrick3345a682010-10-19 14:37:37 +01007#pragma once
Patrick Scottc7f5f852010-02-04 10:37:17 -05008
Kristian Monsenddb351d2011-06-28 21:49:31 +01009#include "base/base_api.h"
Patrick Scottc7f5f852010-02-04 10:37:17 -050010#include "base/basictypes.h"
11
12namespace base {
13
14// Returns a random number in range [0, kuint64max]. Thread-safe.
Kristian Monsenddb351d2011-06-28 21:49:31 +010015BASE_API uint64 RandUint64();
Patrick Scottc7f5f852010-02-04 10:37:17 -050016
17// Returns a random number between min and max (inclusive). Thread-safe.
Kristian Monsenddb351d2011-06-28 21:49:31 +010018BASE_API int RandInt(int min, int max);
Patrick Scottc7f5f852010-02-04 10:37:17 -050019
Iain Merrick3345a682010-10-19 14:37:37 +010020// Returns a random number in range [0, max). Thread-safe.
21//
22// Note that this can be used as an adapter for std::random_shuffle():
23// Given a pre-populated |std::vector<int> myvector|, shuffle it as
24// std::random_shuffle(myvector.begin(), myvector.end(), base::RandGenerator);
Kristian Monsenddb351d2011-06-28 21:49:31 +010025BASE_API uint64 RandGenerator(uint64 max);
Iain Merrick3345a682010-10-19 14:37:37 +010026
Patrick Scottc7f5f852010-02-04 10:37:17 -050027// Returns a random double in range [0, 1). Thread-safe.
Kristian Monsenddb351d2011-06-28 21:49:31 +010028BASE_API double RandDouble();
Patrick Scottc7f5f852010-02-04 10:37:17 -050029
30} // namespace base
31
32#endif // BASE_RAND_UTIL_H_