Cockatrice/common/rng_sfmt.h
RickyRister aee68f8b00
Some checks are pending
Build Desktop / Configure (push) Waiting to run
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Debian, DEB, 12) (push) Blocked by required conditions
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Debian, DEB, skip, 11) (push) Blocked by required conditions
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Fedora, RPM, 41) (push) Blocked by required conditions
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Fedora, RPM, skip, 40) (push) Blocked by required conditions
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Ubuntu, DEB, 24.04) (push) Blocked by required conditions
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Ubuntu, DEB, skip, 20.04) (push) Blocked by required conditions
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Ubuntu, DEB, skip, 22.04) (push) Blocked by required conditions
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (yes, Arch, skip) (push) Blocked by required conditions
Build Desktop / macOS ${{matrix.target}}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }} (3, 1, macos-14, Apple, 14, Release, 15.4) (push) Blocked by required conditions
Build Desktop / macOS ${{matrix.target}}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }} (3, 1, macos-15, Apple, 15, Release, 16.2) (push) Blocked by required conditions
Build Desktop / macOS ${{matrix.target}}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }} (3, macos-15, Apple, 15, Debug, 16.2) (push) Blocked by required conditions
Build Desktop / macOS ${{matrix.target}}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }} (4, 1, macos-13, Intel, 13, Release, 14.3.1) (push) Blocked by required conditions
Build Desktop / Windows ${{matrix.target}} (msvc2019_64, 5.15.*, 7) (push) Blocked by required conditions
Build Desktop / Windows ${{matrix.target}} (msvc2019_64, qtimageformats qtmultimedia qtwebsockets, 6.6.*, 10) (push) Blocked by required conditions
add missing override and explicit specifiers in common (#5527)
2025-01-25 14:06:03 +00:00

44 lines
1.3 KiB
C++

#ifndef RNG_SFMT_H
#define RNG_SFMT_H
#include "rng_abstract.h"
#include "sfmt/SFMT.h"
#include <QMutex>
#include <climits>
/**
* This class encapsulates a state of the art PRNG and can be used
* to return uniformly distributed integer random numbers from a range [min, max].
* Though technically possible, min must be >= 0 and max should always be > 0.
* If max < 0 and min == 0 it is assumed that rand() % -max is wanted and the result will
* be -rand(0, -max).
* This is the only exception to the rule that !(min > max) and is actually unused in
* Cockatrice.
*
* Technical details:
* The RNG uses the SIMD-oriented Fast Mersenne Twister code v1.4.1 from
* http://www.math.sci.hiroshima-u.ac.jp/~%20m-mat/MT/SFMT/index.html
* The SFMT RNG creates unsigned int 64bit pseudo random numbers.
*
* These are mapped to values from the interval [min, max] without bias by using Knuth's
* "Algorithm S (Selection sampling technique)" from "The Art of Computer Programming 3rd
* Edition Volume 2 / Seminumerical Algorithms".
*/
class RNG_SFMT : public RNG_Abstract
{
Q_OBJECT
private:
QMutex mutex;
sfmt_t sfmt;
// The discrete cumulative distribution function for the RNG
unsigned int cdf(unsigned int min, unsigned int max);
public:
explicit RNG_SFMT(QObject *parent = nullptr);
unsigned int rand(int min, int max) override;
};
#endif