Wiselib
wiselib.testing/external_interface/shawn/shawn_rand.h
Go to the documentation of this file.
00001 /***************************************************************************
00002  ** This file is part of the generic algorithm library Wiselib.           **
00003  ** Copyright (C) 2008,2009 by the Wisebed (www.wisebed.eu) project.      **
00004  **                                                                       **
00005  ** The Wiselib is free software: you can redistribute it and/or modify   **
00006  ** it under the terms of the GNU Lesser General Public License as        **
00007  ** published by the Free Software Foundation, either version 3 of the    **
00008  ** License, or (at your option) any later version.                       **
00009  **                                                                       **
00010  ** The Wiselib is distributed in the hope that it will be useful,        **
00011  ** but WITHOUT ANY WARRANTY; without even the implied warranty of        **
00012  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         **
00013  ** GNU Lesser General Public License for more details.                   **
00014  **                                                                       **
00015  ** You should have received a copy of the GNU Lesser General Public      **
00016  ** License along with the Wiselib.                                       **
00017  ** If not, see <http://www.gnu.org/licenses/>.                           **
00018  ***************************************************************************/
00019 #ifndef CONNECTOR_SHAWN_RANDMODEL_H
00020 #define CONNECTOR_SHAWN_RANDMODEL_H
00021 
00022 #include <cstdlib>
00023 
00024 namespace wiselib
00025 {
00026    template<typename OsModel_P>
00027    class ShawnRandModel
00028    {
00029    public:
00030       typedef OsModel_P OsModel;
00031       typedef int rand_t;
00032       typedef ShawnRandModel<OsModel> self_type;
00033       typedef self_type* self_pointer_t;
00034 
00035       typedef int value_t;
00036       // --------------------------------------------------------------------
00037       enum { RANDOM_MAX = RAND_MAX };
00038       // --------------------------------------------------------------------
00039       ShawnRandModel( ShawnOs& os )
00040          : os_(os)
00041       {}
00042       // --------------------------------------------------------------------
00043       ShawnRandModel( ShawnOs& os, value_t seed )
00044          : os_( &os )
00045       {
00046          std::srand( seed );
00047       }
00048       // --------------------------------------------------------------------
00049       void srand( value_t seed )
00050       {
00051          std::srand( seed );
00052       }
00053       // --------------------------------------------------------------------
00054       value_t operator()()
00055       {
00056          return std::rand();
00057       }
00058       // --------------------------------------------------------------------
00059       value_t operator()(value_t max) {
00060          return std::rand()%max;
00061       }
00062    private:
00063       ShawnOs& os()
00064       { return os_; }
00065       // --------------------------------------------------------------------
00066       ShawnOs& os_;
00067    };
00068 
00069 }
00070 
00071 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines