Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_random_source.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include "kis_random_source.h"
8
9#include <boost/random/normal_distribution.hpp>
10#include <boost/random/taus88.hpp>
11#include <boost/random/uniform_smallint.hpp>
12
13#include <QRandomGenerator>
14
16{
18 : uniformSource(QRandomGenerator::global()->generate()) {}
19
20 Private(int seed)
21 : uniformSource(seed) {}
22
29 boost::taus88 uniformSource;
30};
31
32
37
39 : m_d(new Private(seed))
40{
41}
42
44 : KisShared(),
45 m_d(new Private(*rhs.m_d))
46{
47}
48
50{
51 if (this != &rhs) {
52 *m_d = *rhs.m_d;
53 }
54
55 return *this;
56}
57
61
63{
64 return m_d->uniformSource();
65}
66
67int KisRandomSource::generate(int min, int max) const
68{
69 boost::uniform_smallint<int> smallint(min, max);
70 return smallint(m_d->uniformSource);
71}
72
74{
75 const qint64 v = m_d->uniformSource();
76 const qint64 max = m_d->uniformSource.max();
77 // we don't have min, because taus88 is always positive
78
79 return qreal(v) / max;
80}
81
82qreal KisRandomSource::generateGaussian(qreal mean, qreal sigma) const
83{
84 boost::normal_distribution<qreal> normal(mean, sigma);
85 return normal(m_d->uniformSource);
86}
qreal v
qreal generateNormalized() const
const QScopedPointer< Private > m_d
qreal generateGaussian(qreal mean, qreal sigma) const
qint64 generate() const
KisRandomSource & operator=(const KisRandomSource &rhs)