Krita Source Code Documentation
Loading...
Searching...
No Matches
KisRandomSource Class Reference

#include <kis_random_source.h>

+ Inheritance diagram for KisRandomSource:

Classes

struct  Private
 

Public Member Functions

qint64 generate () const
 
int generate (int min, int max) const
 
qreal generateGaussian (qreal mean, qreal sigma) const
 
qreal generateNormalized () const
 
 KisRandomSource ()
 
 KisRandomSource (const KisRandomSource &rhs)
 
 KisRandomSource (int seed)
 
KisRandomSourceoperator= (const KisRandomSource &rhs)
 
 ~KisRandomSource ()
 
- Public Member Functions inherited from KisShared
bool deref ()
 
bool ref ()
 
int refCount ()
 
QAtomicInt * sharedWeakReference ()
 

Private Attributes

const QScopedPointer< Privatem_d
 

Additional Inherited Members

- Protected Member Functions inherited from KisShared
 KisShared ()
 
 ~KisShared ()
 

Detailed Description

KisRandomSource is a special object that wraps around random number generation routines.

It has the following properties:

1) Two KisRandomSource objects will generate exactly the same sequences of numbers if created with the same seed.

2) After copy-construction or assignment the two objects will continue to generate exactly the same numbers. Imagine like the history got forked.

3) Copying of a KisRandomSource object is fast. It uses Tauss88 algorithm to achieve this.

Definition at line 32 of file kis_random_source.h.

Constructor & Destructor Documentation

◆ KisRandomSource() [1/3]

KisRandomSource::KisRandomSource ( )

Definition at line 33 of file kis_random_source.cpp.

34 : m_d(new Private)
35{
36}
const QScopedPointer< Private > m_d

◆ KisRandomSource() [2/3]

KisRandomSource::KisRandomSource ( int seed)

Definition at line 38 of file kis_random_source.cpp.

39 : m_d(new Private(seed))
40{
41}

◆ KisRandomSource() [3/3]

KisRandomSource::KisRandomSource ( const KisRandomSource & rhs)

Definition at line 43 of file kis_random_source.cpp.

44 : KisShared(),
45 m_d(new Private(*rhs.m_d))
46{
47}

◆ ~KisRandomSource()

KisRandomSource::~KisRandomSource ( )

Definition at line 58 of file kis_random_source.cpp.

59{
60}

Member Function Documentation

◆ generate() [1/2]

qint64 KisRandomSource::generate ( ) const

Generates a random number in a range from min() to max()

Definition at line 62 of file kis_random_source.cpp.

63{
64 return m_d->uniformSource();
65}

References m_d.

◆ generate() [2/2]

int KisRandomSource::generate ( int min,
int max ) const

Generates a random number in a range from min to max

Definition at line 67 of file kis_random_source.cpp.

68{
69 boost::uniform_smallint<int> smallint(min, max);
70 return smallint(m_d->uniformSource);
71}

References m_d.

◆ generateGaussian()

qreal KisRandomSource::generateGaussian ( qreal mean,
qreal sigma ) const

Generates a number from the Gaussian distribution

Definition at line 82 of file kis_random_source.cpp.

83{
84 boost::normal_distribution<qreal> normal(mean, sigma);
85 return normal(m_d->uniformSource);
86}

References m_d.

◆ generateNormalized()

qreal KisRandomSource::generateNormalized ( ) const

Generates a random number in a closed range [0; 1.0]

Definition at line 73 of file kis_random_source.cpp.

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}
qreal v
constexpr std::enable_if< sizeof...(values)==0, size_t >::type max()

References m_d, and v.

◆ operator=()

KisRandomSource & KisRandomSource::operator= ( const KisRandomSource & rhs)

Definition at line 49 of file kis_random_source.cpp.

50{
51 if (this != &rhs) {
52 *m_d = *rhs.m_d;
53 }
54
55 return *this;
56}

References m_d.

Member Data Documentation

◆ m_d

const QScopedPointer<Private> KisRandomSource::m_d
private

Definition at line 64 of file kis_random_source.h.


The documentation for this class was generated from the following files: