source: trunk/lib/utility/random_singleton.cc @ 358

Last change on this file since 358 was 358, checked in by Peter, 17 years ago

cleaned up in random_singleton

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.1 KB
Line 
1// $Id: random_singleton.cc 358 2005-08-03 16:09:44Z peter $
2
3#include <c++_tools/utility/random_singleton.h>
4
5namespace theplu {
6namespace utility { 
7
8// Static members
9//////////////////
10random_singleton* random_singleton::singleobj_ = NULL;
11
12
13// Constructors and destructors
14///////////////////////////////
15random_singleton::random_singleton()
16{
17  const gsl_rng_type* T;
18  gsl_rng_env_setup();
19  T = gsl_rng_default;
20  r_ = gsl_rng_alloc( T );  // Memory is allocated here!
21  gen_ = NULL;   // Only to be used in the general purpose distribution
22}
23
24
25random_singleton::~random_singleton()
26{
27  gsl_rng_free( r_ );
28  r_ = NULL;
29  if( gen_ != 0 ) gsl_ran_discrete_free( gen_ );
30  gen_ = NULL;
31}
32
33
34void random_singleton::seed( const int& seed )
35{
36  if( seed < 0 ) 
37    {
38     gsl_rng_set( r_, time( 0 ) ); 
39    }
40  else
41    {
42     gsl_rng_set( r_, seed );
43    }
44}
45
46
47random_singleton* random_singleton::instance( int seed )
48{
49  if( !singleobj_ ) 
50    {
51     singleobj_ = new random_singleton();
52     singleobj_->seed( seed );
53    }
54  return singleobj_;
55}
56
57/**
58double random_singleton::get_poisson(const double m) const
59{
60 
61}
62*/
63
64}} // of namespace utility and namespace theplu
Note: See TracBrowser for help on using the repository browser.