simple_rng.hpp

Go to the documentation of this file.
00001 /* $Id: simple_rng.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2003 by David White <dave@whitevine.net>
00004    Copyright (C) 2005 - 2012 by Yann Dirson <ydirson@altern.org>
00005    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
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    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY.
00013 
00014    See the COPYING file for more details.
00015 */
00016 
00017 #ifndef SIMPLE_RNG_HPP_INCLUDED
00018 #define SIMPLE_RNG_HPP_INCLUDED
00019 
00020 class config;
00021 
00022 namespace rand_rng
00023 {
00024 
00025 class simple_rng
00026 {
00027 public:
00028     simple_rng();
00029     simple_rng(const config& cfg);
00030 
00031     /** Get a new random number. */
00032     int get_next_random();
00033 
00034     /**
00035      *  Seeds the random pool.
00036      *
00037      *  @param call_count   Upon loading we need to restore the state at saving
00038      *                      so set the number of times a random number is
00039      *                      generated for replays the orginal value is
00040      *                      required.
00041      */
00042     void seed_random(const unsigned call_count = 0);
00043 
00044     /**
00045      *  Seeds the random pool.
00046      *
00047      *  @param seed         The initial value for the random engine.
00048      *  @param call_count   Upon loading we need to restore the state at saving
00049      *                      so set the number of times a random number is
00050      *                      generated for replays the orginal value is
00051      *                      required.
00052      */
00053     void seed_random(const int seed, const unsigned call_count = 0);
00054 
00055     /**
00056      * Resets the random to the 0 calls and the seed to the random
00057      *  this way we stay in the same sequence but don't have a lot
00058      *  calls. Used when moving to the next scenario.
00059      */
00060     void rotate_random();
00061 
00062     int get_random_seed() const { return random_seed_; }
00063     int get_random_calls() const { return random_calls_; }
00064 
00065 private:
00066     /** Initial seed for the pool. */
00067     int random_seed_;
00068 
00069     /** State for the random pool (modulo arithmetic). */
00070     unsigned random_pool_;
00071 
00072     /** Number of time a random number is generated. */
00073     unsigned random_calls_;
00074 
00075     /** Sets the next random number in the pool. */
00076     void random_next();
00077 };
00078 
00079 } // ends rand_rng namespace
00080 
00081 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:10 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs