Skip to content
Snippets Groups Projects
Select Git revision
  • 966a1c2ac0fb036b331c4d6c9a4adb3a95bd23b3
  • master default protected
  • 6.x protected
  • madysson
  • 5.x protected
  • asm
  • time-varying-information-set
  • 4.6 protected
  • dynare_minreal
  • dragonfly
  • various_fixes
  • 4.5 protected
  • clang+openmp
  • exo_steady_state
  • declare_vars_in_model_block
  • julia
  • error_msg_undeclared_model_vars
  • static_aux_vars
  • slice
  • aux_func
  • penalty
  • 6.4 protected
  • 6.3 protected
  • 6.2 protected
  • 6.1 protected
  • 6.0 protected
  • 6-beta2 protected
  • 6-beta1 protected
  • 5.5 protected
  • 5.4 protected
  • 5.3 protected
  • 5.2 protected
  • 5.1 protected
  • 5.0 protected
  • 5.0-rc1 protected
  • 4.7-beta3 protected
  • 4.7-beta2 protected
  • 4.7-beta1 protected
  • 4.6.4 protected
  • 4.6.3 protected
  • 4.6.2 protected
41 results

quadrature-points.cc

Blame
  • random.cweb 1.23 KiB
    @q $Id: random.cweb 1491 2007-12-19 14:36:53Z kamenik $ @>
    @q Copyright 2007, Ondra Kamenik @>
    
    @ Start of {\tt random.cpp} file.
    @c
    
    #include "random.h"
    
    #include <cstdlib>
    #include <limits>
    #include <cmath>
    
    @<|RandomGenerator::int_uniform| code@>;
    @<|RandomGenerator::normal| code@>;
    SystemRandomGenerator system_random_generator;
    @<|SystemRandomGenerator::uniform| code@>;
    @<|SystemRandomGenerator::initSeed| code@>;
    
    @ 
    @<|RandomGenerator::int_uniform| code@>=
    int RandomGenerator::int_uniform()
    {
    	double s = std::numeric_limits<int>::max()*uniform();
    	return (int)s;
    }
    
    @ This implements Marsaglia Polar Method. 
    @<|RandomGenerator::normal| code@>=
    double RandomGenerator::normal()
    {
    	double x1, x2;
    	double w;
    	do {
    		x1 = 2*uniform()-1;
    		x2 = 2*uniform()-1;
    		w = x1*x1 + x2*x2;
    	} while (w >= 1.0 || w < 1.0e-30);
    	return x1*std::sqrt((-2.0*std::log(w))/w);
    }
    
    @ 
    @<|SystemRandomGenerator::uniform| code@>=
    double SystemRandomGenerator::uniform()
    {
    #if !defined(__MINGW32__)
    	return drand48();
    #else
    	return ((double)rand())/RAND_MAX;
    #endif
    }
    
    @ 
    @<|SystemRandomGenerator::initSeed| code@>=
    void SystemRandomGenerator::initSeed(int seed)
    {
    #if !defined(__MINGW32__)
    	srand48(seed);
    #else
    	srand(seed);
    #endif
    }
    
    @ End of {\tt random.cpp} file.