Robotsystem of the Robot Group Leipzig: randomgenerator.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

- File List
- File Members

# randomgenerator.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
    00003  *    martius@informatik.uni-leipzig.de                                    *
    00004  *    fhesse@informatik.uni-leipzig.de                                     *
    00005  *    der@informatik.uni-leipzig.de                                        *
    00006  *                                                                         *
    00007  *   This program is free software; you can redistribute it and/or modify  *
    00008  *   it under the terms of the GNU General Public License as published by  *
    00009  *   the Free Software Foundation; either version 2 of the License, or     *
    00010  *   (at your option) any later version.                                   *
    00011  *                                                                         *
    00012  *   This program is distributed in the hope that it will be useful,       *
    00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00015  *   GNU General Public License for more details.                          *
    00016  *                                                                         *
    00017  *   You should have received a copy of the GNU General Public License     *
    00018  *   along with this program; if not, write to the                         *
    00019  *   Free Software Foundation, Inc.,                                       *
    00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00021  *                                                                         *
    00022  *   Random generator with internal state used for multitheading envs.     *
    00023  *                                                                         *
    00024  *   $Log: randomgenerator.h,v $
    00025  *   Revision 1.2  2008/04/17 14:54:45  martius
    00026  *   randomGen added, which is a random generator with long period and an
    00027  *    internal state. Each Agent has an instance and passed it to the controller
    00028  *    and the wiring. This is good for
    00029  *   a) repeatability on agent basis,
    00030  *   b) parallel execution as done in ode_robots
    00031  *
    00032  *   Revision 1.1  2008/04/15 17:03:34  martius
    00033  *   random generator with state
    00034  *
    00035  ***************************************************************************/
    00036 #ifndef __RANDOMGENERATOR_H
    00037 #define __RANDOMGENERATOR_H
    00038
    00039 #include <stdlib.h>
    00040
    00041 typedef struct _RandGen {
    00042   _RandGen(){
    00043     init(::rand());
    00044   }
    00045   void init(long int seedval){
    00046     srand48_r(seedval, &buffer);
    00047   }
    00048   double rand(){
    00049     double r;
    00050     drand48_r(&buffer,&r);
    00051     return r;
    00052   }
    00053   struct drand48_data buffer;
    00054 } RandGen;
    00055
    00056 #endif