00001 // Copyright 2010-2012 Google00002 // Licensed under the Apache License, Version 2.0 (the "License");00003 // you may not use this file except in compliance with the License.00004 // You may obtain a copy of the License at00005 //00006 // http://www.apache.org/licenses/LICENSE-2.000007 //00008 // Unless required by applicable law or agreed to in writing, software00009 // distributed under the License is distributed on an "AS IS" BASIS,00010 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.00011 // See the License for the specific language governing permissions and00012 // limitations under the License.00013
00014 #ifndef OR_TOOLS_BASE_RANDOM_H_00015 #define OR_TOOLS_BASE_RANDOM_H_00016
00017 #include "base/basictypes.h"00018
00019 namespace operations_research {
00020
00021 // ACM minimal standard random number generator. (re-entrant.)00022class ACMRandom {
00023 public:
00024explicitACMRandom(int32 seed) : seed_(seed) {}
00025 int32Next();
00026 int32Uniform(int32 max_value);
00027 int64Next64();
00028floatRndFloat() {
00029 returnNext() * 0.000000000465661273646; // x: x * (M-1) = 1 - eps00030 }
00031
00032voidReset(int32 seed) { seed_ = seed; }
00033 staticint32HostnamePidTimeSeed();
00034 staticint32DeterministicSeed();
00035
00036 private:
00037 int32 seed_;
00038 };
00039
00040 } // namespace operations_research00041
00042 #endif // OR_TOOLS_BASE_RANDOM_H_