Skip to content

Commit

Permalink
Added copyright note for reference impl and brief documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfkonrad committed Aug 16, 2023
1 parent 9c6796c commit 627bd75
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions ql/math/randomnumbers/xoshiro256starstaruniformrng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit 627bd75

Please sign in to comment.