QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
knuthuniformrng.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
24#ifndef quantlib_knuth_uniform_rng_h
25#define quantlib_knuth_uniform_rng_h
26
27#include <ql/methods/montecarlo/sample.hpp>
28#include <vector>
29
30namespace QuantLib {
31
33
45 public:
49 explicit KnuthUniformRng(long seed = 0);
52 sample_type next() const;
53 private:
54 static const int KK, LL, TT, QUALITY;
55 mutable std::vector<double> ranf_arr_buf;
57 mutable std::vector<double> ran_u;
58 double mod_sum(double x, double y) const;
59 bool is_odd(int s) const;
60 void ranf_start(long seed);
61 void ranf_array(std::vector<double>& aa, int n) const;
62 double ranf_arr_cycle() const;
63 };
64
65
66 // inline definitions
67
69 double result = (ranf_arr_ptr != ranf_arr_sentinel ?
72 return {result, 1.0};
73 }
74
75 inline double KnuthUniformRng::mod_sum(double x, double y) const {
76 return (x+y)-int(x+y);
77 }
78
79 inline bool KnuthUniformRng::is_odd(int s) const {
80 return (s&1) != 0;
81 }
82
83}
84
85
86#endif
Uniform random number generator.
void ranf_array(std::vector< double > &aa, int n) const
sample_type next() const
double mod_sum(double x, double y) const
std::vector< double > ran_u
std::vector< double > ranf_arr_buf
Definition: any.hpp:35
weighted sample
Definition: sample.hpp:35