SUMO - Simulation of Urban MObility
RandHelper.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00008 //
00009 /****************************************************************************/
00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00012 /****************************************************************************/
00013 //
00014 //   This file is part of SUMO.
00015 //   SUMO is free software: you can redistribute it and/or modify
00016 //   it under the terms of the GNU General Public License as published by
00017 //   the Free Software Foundation, either version 3 of the License, or
00018 //   (at your option) any later version.
00019 //
00020 /****************************************************************************/
00021 
00022 
00023 // ===========================================================================
00024 // included modules
00025 // ===========================================================================
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031 
00032 #include <utils/options/OptionsCont.h>
00033 #include "RandHelper.h"
00034 #include <ctime>
00035 #include <cmath>
00036 
00037 #ifdef CHECK_MEMORY_LEAKS
00038 #include <foreign/nvwa/debug_new.h>
00039 #endif // CHECK_MEMORY_LEAKS
00040 
00041 
00042 // ===========================================================================
00043 // static member variables
00044 // ===========================================================================
00045 MTRand RandHelper::myRandomNumberGenerator;
00046 
00047 
00048 // ===========================================================================
00049 // member method definitions
00050 // ===========================================================================
00051 void
00052 RandHelper::insertRandOptions() {
00053     OptionsCont& oc = OptionsCont::getOptions();
00054     // registers random number options
00055     oc.addOptionSubTopic("Random Number");
00056 
00057     oc.doRegister("random", new Option_Bool(false));
00058     oc.addSynonyme("random", "abs-rand", true);
00059     oc.addDescription("random", "Random Number", "Initialises the random number generator with the current system time");
00060 
00061     oc.doRegister("seed", new Option_Integer(23423));
00062     oc.addSynonyme("seed", "srand", true);
00063     oc.addDescription("seed", "Random Number", "Initialises the random number generator with the given value");
00064 }
00065 
00066 
00067 void
00068 RandHelper::initRandGlobal() {
00069     OptionsCont& oc = OptionsCont::getOptions();
00070     if (oc.getBool("random")) {
00071         myRandomNumberGenerator.seed();
00072     } else {
00073         myRandomNumberGenerator.seed(oc.getInt("seed"));
00074     }
00075 }
00076 
00077 
00078 /****************************************************************************/
00079 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines