File indexing completed on 2025-02-02 04:15:57
0001 /* 0002 * SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef __KIS_RANDOM_SOURCE_H 0008 #define __KIS_RANDOM_SOURCE_H 0009 0010 #include <QScopedPointer> 0011 #include "kis_shared.h" 0012 #include "kis_shared_ptr.h" 0013 0014 #include "kritaimage_export.h" 0015 0016 /** 0017 * KisRandomSource is a special object that wraps around random number 0018 * generation routines. 0019 * 0020 * It has the following properties: 0021 * 0022 * 1) Two KisRandomSource objects will generate exactly the same sequences of 0023 * numbers if created with the same seed. 0024 * 0025 * 2) After copy-construction or assignment the two objects will 0026 * continue to generate exactly the same numbers. Imagine like the 0027 * history got forked. 0028 * 0029 * 3) Copying of a KisRandomSource object is fast. It uses Tauss88 0030 * algorithm to achieve this. 0031 */ 0032 class KRITAIMAGE_EXPORT KisRandomSource : public KisShared 0033 { 0034 public: 0035 KisRandomSource(); 0036 KisRandomSource(int seed); 0037 KisRandomSource(const KisRandomSource &rhs); 0038 KisRandomSource& operator=(const KisRandomSource &rhs); 0039 0040 ~KisRandomSource(); 0041 0042 /** 0043 * Generates a random number in a range from min() to max() 0044 */ 0045 qint64 generate() const; 0046 0047 /** 0048 * Generates a random number in a range from \p min to \p max 0049 */ 0050 int generate(int min, int max) const; 0051 0052 /** 0053 * Generates a random number in a closed range [0; 1.0] 0054 */ 0055 qreal generateNormalized() const; 0056 0057 /** 0058 * Generates a number from the Gaussian distribution 0059 */ 0060 qreal generateGaussian(qreal mean, qreal sigma) const; 0061 0062 private: 0063 struct Private; 0064 const QScopedPointer<Private> m_d; 0065 }; 0066 0067 class KisRandomSource; 0068 typedef KisSharedPtr<KisRandomSource> KisRandomSourceSP; 0069 typedef KisWeakSharedPtr<KisRandomSource> KisRandomSourceWSP; 0070 0071 #endif /* __KIS_RANDOM_SOURCE_H */