2014-02-10 16:01:39 +00:00
|
|
|
/*
|
|
|
|
* RandGen.hpp, part of LatAnalyze 3
|
|
|
|
*
|
2015-06-11 14:04:54 +01:00
|
|
|
* Copyright (C) 2013 - 2015 Antonin Portelli
|
2014-02-10 16:01:39 +00:00
|
|
|
*
|
|
|
|
* LatAnalyze 3 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* LatAnalyze 3 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef Latan_RandGen_hpp_
|
|
|
|
#define Latan_RandGen_hpp_
|
|
|
|
|
2014-03-13 18:51:01 +00:00
|
|
|
#include <LatAnalyze/Global.hpp>
|
|
|
|
#include <LatAnalyze/IoObject.hpp>
|
2014-02-10 16:01:39 +00:00
|
|
|
|
2014-02-17 18:50:03 +00:00
|
|
|
#define RLXG_STATE_SIZE 105u
|
2014-02-10 16:01:39 +00:00
|
|
|
|
2015-01-28 17:15:05 +00:00
|
|
|
BEGIN_LATAN_NAMESPACE
|
2014-02-10 16:01:39 +00:00
|
|
|
|
2014-02-26 18:36:29 +00:00
|
|
|
class RandGenState: public Array<int, RLXG_STATE_SIZE, 1>,
|
2014-02-20 23:52:45 +00:00
|
|
|
public IoObject
|
|
|
|
{
|
|
|
|
private:
|
2014-02-26 18:36:29 +00:00
|
|
|
typedef Array<int, RLXG_STATE_SIZE, 1> Base;
|
2014-02-20 23:52:45 +00:00
|
|
|
public:
|
|
|
|
// destructor
|
|
|
|
virtual ~RandGenState(void) = default;
|
|
|
|
// IO type
|
|
|
|
IoType getType(void) const;
|
|
|
|
};
|
|
|
|
|
2014-02-10 16:01:39 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* Random generator class *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class RandGen
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
// Martin Luescher's ranlxd generator interface
|
|
|
|
class RanLxd
|
|
|
|
{
|
|
|
|
private:
|
2014-03-03 14:21:37 +00:00
|
|
|
typedef struct alignas(16)
|
2014-02-10 16:01:39 +00:00
|
|
|
{
|
|
|
|
float c1,c2,c3,c4;
|
2014-03-03 14:21:37 +00:00
|
|
|
} rlxd_vec_t;
|
|
|
|
typedef struct alignas(16)
|
2014-02-10 16:01:39 +00:00
|
|
|
{
|
|
|
|
rlxd_vec_t c1,c2;
|
2014-03-03 14:21:37 +00:00
|
|
|
} rlxd_dble_vec_t;
|
2014-02-10 16:01:39 +00:00
|
|
|
public:
|
|
|
|
RanLxd(void);
|
2014-02-20 22:54:11 +00:00
|
|
|
~RanLxd(void) = default;
|
2014-02-10 16:01:39 +00:00
|
|
|
void ranlxd(double r[],int n);
|
|
|
|
void rlxd_init(int level,int seed);
|
|
|
|
int rlxd_size(void) const;
|
|
|
|
void rlxd_get(int state[]) const;
|
|
|
|
void rlxd_reset(const int state[]);
|
|
|
|
private:
|
|
|
|
void error(int no) const;
|
|
|
|
void update(void);
|
|
|
|
void define_constants(void);
|
|
|
|
private:
|
2014-03-03 14:21:37 +00:00
|
|
|
int init{0}, rlxd_pr, prm, ir, jr, is, is_old, next[96];
|
2014-02-10 16:01:39 +00:00
|
|
|
rlxd_vec_t one_sse, one_bit_sse, carry;
|
|
|
|
double one_bit;
|
2014-03-03 14:21:37 +00:00
|
|
|
union alignas(16)
|
2014-02-10 16:01:39 +00:00
|
|
|
{
|
|
|
|
rlxd_dble_vec_t vec[12];
|
|
|
|
float num[96];
|
2014-03-03 14:21:37 +00:00
|
|
|
} rlxd_x;
|
2014-02-10 16:01:39 +00:00
|
|
|
};
|
|
|
|
public:
|
|
|
|
// constructors
|
|
|
|
RandGen(void);
|
2014-03-03 14:21:37 +00:00
|
|
|
explicit RandGen(const int seed);
|
|
|
|
explicit RandGen(const RandGenState &state);
|
2014-02-10 16:01:39 +00:00
|
|
|
// destructor
|
2014-02-20 22:54:11 +00:00
|
|
|
virtual ~RandGen(void) = default;
|
2014-02-10 16:01:39 +00:00
|
|
|
// state management
|
2014-02-20 23:52:45 +00:00
|
|
|
RandGenState getState(void) const;
|
|
|
|
void setState(const RandGenState &state);
|
2014-02-10 16:01:39 +00:00
|
|
|
// generators
|
|
|
|
double uniform(const double a = 0.0, const double b = 1.0);
|
2015-01-28 17:15:05 +00:00
|
|
|
unsigned int discreteUniform(const unsigned int n);
|
2014-02-10 16:01:39 +00:00
|
|
|
double gaussian(const double mean = 0.0, const double sigma = 1.0);
|
|
|
|
private:
|
|
|
|
RanLxd generator_;
|
|
|
|
};
|
|
|
|
|
2015-01-28 17:15:05 +00:00
|
|
|
END_LATAN_NAMESPACE
|
2014-02-10 16:01:39 +00:00
|
|
|
|
|
|
|
#endif // Latan_RandGen_hpp_
|