Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added convenience class ZigguratXoshiro256StarStarGaussianRng #1991

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ql/math/randomnumbers/zigguratgaussianrng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#ifndef quantlib_ziggurat_gaussian_rng_h
#define quantlib_ziggurat_gaussian_rng_h

#include <ql/math/randomnumbers/xoshiro256starstaruniformrng.hpp>
#include <ql/methods/montecarlo/sample.hpp>
#include <cstdint>

Expand Down Expand Up @@ -81,6 +82,18 @@ namespace QuantLib {
Real normF(int i) const;
};


//! Gaussian random number generator
/*! As Xoshiro256StarStarUniformRng is currently the only RNG supporting the above interface,
we provide a convenience class that uses it.
*/
class ZigguratXoshiro256StarStarGaussianRng
: public ZigguratGaussianRng<Xoshiro256StarStarUniformRng> {
public:
explicit ZigguratXoshiro256StarStarGaussianRng(BigNatural seed = 0)
: ZigguratGaussianRng<Xoshiro256StarStarUniformRng>(Xoshiro256StarStarUniformRng(seed)) {}
};

template <class RNG>
inline Real ZigguratGaussianRng<RNG>::nextReal() const {
while (true) {
Expand Down
6 changes: 2 additions & 4 deletions test-suite/zigguratgaussian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

#include "toplevelfixture.hpp"
#include <ql/math/randomnumbers/xoshiro256starstaruniformrng.hpp>
#include <ql/math/randomnumbers/zigguratgaussianrng.hpp>
#include <ql/math/statistics/incrementalstatistics.hpp>
#include <iostream>
Expand All @@ -31,11 +30,10 @@ BOOST_FIXTURE_TEST_SUITE(QuantLibTests, TopLevelFixture)
BOOST_AUTO_TEST_SUITE(ZigguratGaussianTests)

BOOST_AUTO_TEST_CASE(testStatisticsOfNextReal) {
BOOST_TEST_MESSAGE("Testing ZigguratGaussianRng<Xoshiro256StarStarUniformRng>::nextReal() for "
BOOST_TEST_MESSAGE("Testing ZigguratXoshiro256StarStarGaussianRng::nextReal() for "
"mean, variance, skewness and kurtosis...");
auto seed = 42UL;
auto uniformRandom = Xoshiro256StarStarUniformRng(seed);
auto random = ZigguratGaussianRng<Xoshiro256StarStarUniformRng>(uniformRandom);
auto random = ZigguratXoshiro256StarStarGaussianRng(seed);

auto randoms = IncrementalStatistics();

Expand Down
Loading