-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added copyright note for reference impl and brief documentation
- Loading branch information
1 parent
9c6796c
commit 627bd75
Showing
1 changed file
with
32 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,18 +17,47 @@ | |
FOR A PARTICULAR PURPOSE. See the license for more details. | ||
*/ | ||
|
||
// NOTE: The following copyright notice applies to the | ||
// original C implementation https://prng.di.unimi.it/xoshiro256starstar.c | ||
// that has been used for this class. | ||
|
||
/* Written in 2018 by David Blackman and Sebastiano Vigna ([email protected]) | ||
To the extent possible under law, the author has dedicated all copyright | ||
and related and neighboring rights to this software to the public domain | ||
worldwide. This software is distributed without any warranty. | ||
See <http://creativecommons.org/publicdomain/zero/1.0/>. */ | ||
|
||
/*! \file xoshiro256starstaruniformrng.hpp | ||
\brief xoshiro256** uniform random number generator | ||
*/ | ||
|
||
#ifndef quantlib_xoshiro256starstar_uniform_rng_hpp | ||
#define quantlib_xoshiro256starstar_uniform_rng_hpp | ||
|
||
#include <ql/methods/montecarlo/sample.hpp> | ||
#include <ql/types.hpp> | ||
|
||
namespace QuantLib { | ||
|
||
//! Uniform random number generator | ||
/*! xoshiro256** random number generator of period 2**256-1 | ||
* | ||
* For more details see | ||
* https://prng.di.unimi.it/ | ||
* and its reference implementation | ||
* https://prng.di.unimi.it/xoshiro256starstar.c | ||
* | ||
* \test the correctness of the returned values is tested by checking them | ||
* against the reference implementation in c. | ||
* */ | ||
|
||
class Xoshiro256StarStarUniformRng { | ||
public: | ||
typedef Sample<Real> sample_type; | ||
/*! if the given seed is 0, a random seed will be chosen | ||
based on clock() */ | ||
|
||
/*! if the given seed is 0, a random seed will be chosen based on clock() */ | ||
explicit Xoshiro256StarStarUniformRng(unsigned long long seed = 0); | ||
|
||
Xoshiro256StarStarUniformRng(unsigned long long s0, | ||
|
@@ -41,7 +70,7 @@ namespace QuantLib { | |
sample_type next() const { return {nextReal(), 1.0}; } | ||
|
||
//! return a random number in the (0.0, 1.0)-interval | ||
Real nextReal() const { return (Real(nextInt64() >> 11) + 0.5) * (1.0 / (1ULL << 53)); } | ||
Real nextReal() const { return (Real(nextInt64() >> 11) + 0.5) * (1.0 / Real(1ULL << 53)); } | ||
|
||
//! return a random integer in the [0,0xffffffffffffffffULL]-interval | ||
unsigned long long nextInt64() const { | ||
|