QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
xoshiro256starstaruniformrng.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2023 Ralf Konrad Eckel
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
22
23namespace QuantLib {
24
25 namespace {
26
27 // NOTE: The following copyright notice applies to the
28 // original C implementation https://prng.di.unimi.it/splitmix64.c
29 // that has been used for this class.
30
31 /* Written in 2015 by Sebastiano Vigna (vigna@acm.org)
32
33 To the extent possible under law, the author has dedicated all copyright
34 and related and neighboring rights to this software to the public domain
35 worldwide. This software is distributed without any warranty.
36
37 See <http://creativecommons.org/publicdomain/zero/1.0/>.
38 */
39 class SplitMix64 {
40 public:
41 explicit SplitMix64(std::uint64_t x) : x_(x) {}
42 std::uint64_t next() const {
43 auto z = (x_ += 0x9e3779b97f4a7c15);
44 z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
45 z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
46 return z ^ (z >> 31);
47 };
48
49 private:
50 mutable std::uint64_t x_;
51 };
52 }
53
55 SplitMix64 splitMix64(seed != 0 ? seed : SeedGenerator::instance().get());
56 s0_ = splitMix64.next();
57 s1_ = splitMix64.next();
58 s2_ = splitMix64.next();
59 s3_ = splitMix64.next();
60 }
61
63 std::uint64_t s1,
64 std::uint64_t s2,
65 std::uint64_t s3)
66 : s0_(s0), s1_(s1), s2_(s2), s3_(s3) {}
67
68}
static SeedGenerator & instance()
access to the unique instance
Definition: singleton.hpp:104
Definition: any.hpp:35
Random seed generator.
std::uint64_t x_
xoshiro256** uniform random number generator