00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- 00002 00003 this file is part of rcssserver3D 00004 Fri May 9 2003 00005 Copyright (C) 2002,2003 Koblenz University 00006 Copyright (C) 2004 RoboCup Soccer Server 3D Maintenance Group 00007 $Id: randomserver.h,v 1.2 2004/02/12 14:07:24 fruit Exp $ 00008 00009 This program is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; version 2 of the License. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00021 00022 */ 00023 #ifndef ZEITGEIST_RANDOMSERVER_H 00024 #define ZEITGEIST_RANDOMSERVER_H 00025 00026 #include <salt/random.h> 00027 #include <zeitgeist/node.h> 00028 #include <sys/time.h> 00029 00030 namespace zeitgeist 00031 { 00032 00037 class RandomServer : public Node 00038 { 00039 public: 00041 RandomServer() {} 00042 00043 virtual ~RandomServer() {} 00044 00046 void Seed(salt::RandomEngine::result_type seed) 00047 { 00048 if (seed == 0) 00049 { 00050 timeval tv; 00051 gettimeofday(&tv,0); 00052 seed = tv.tv_usec; 00053 } 00054 salt::RandomEngine::instance(seed); 00055 } 00056 00058 template<class RealType> 00059 RealType GetUniformRandom(RealType min, RealType max) const 00060 { 00061 return salt::UniformRNG<RealType>(min,max)(); 00062 } 00063 00064 template<class RealType> 00065 RealType GetNormalRandom(RealType mean, RealType sigma) const 00066 { 00067 return salt::NormalRNG<RealType>(mean,sigma)(); 00068 } 00069 00070 template<class RealType> 00071 RealType GetExponentialRandom(RealType lambda) const 00072 { 00073 return salt::ExponentialRNG<RealType>(lambda)(); 00074 } 00075 00076 }; 00077 00078 DECLARE_CLASS(RandomServer); 00079 00080 } //namespace zeitgeist 00081 00082 #endif //ZEITGEIST_LOGSERVER_H