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

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

added classes to random, now has all functionality that former random_singleton had except general distributions

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