MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_random_xorshift.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_RANDOM_H_1626922980
12#define INCGUARD_MGL_RANDOM_H_1626922980
13
14#include <cstdint>
15
16namespace MGL::Random
17{
20{
21public:
22 /* ------------------------------------------------------------------------- */
27 /* ------------------------------------------------------------------------- */
28 constexpr XorShift(uint32_t seed = 0) noexcept
29 : _seed(seed)
30 {}
31
32
33 /* ------------------------------------------------------------------------- */
38 /* ------------------------------------------------------------------------- */
39 constexpr uint32_t Get() noexcept
40 {
41 _seed = _seed ^ (_seed << 13);
42 _seed = _seed ^ (_seed >> 17);
43 _seed = _seed ^ (_seed << 5);
44
45 return _seed;
46 }
47
48 /* ------------------------------------------------------------------------- */
53 /* ------------------------------------------------------------------------- */
54 constexpr float GetFloat() noexcept
55 {
56 return static_cast<float>(static_cast<double>(Get()) / static_cast<double>(0xFFFFFFFF));
57 }
58
59 /* ------------------------------------------------------------------------- */
64 /* ------------------------------------------------------------------------- */
65 constexpr uint32_t GetSeed() const noexcept
66 {
67 return _seed;
68 }
69
70 /* ------------------------------------------------------------------------- */
75 /* ------------------------------------------------------------------------- */
76 constexpr void SetSeed(uint32_t seed) noexcept
77 {
78 _seed = seed;
79 }
80
81private:
82 uint32_t _seed;
83};
84} // namespace MGL::Random
85
86#endif // INCGUARD_MGL_RANDOM_H_1626922980
87
88// vim: et ts=4 sw=4 sts=4
XorShift乱数ジェネレータ
Definition mgl_random_xorshift.h:20
constexpr XorShift(uint32_t seed=0) noexcept
コンストラクタ
Definition mgl_random_xorshift.h:28
constexpr uint32_t GetSeed() const noexcept
種の取得
Definition mgl_random_xorshift.h:65
constexpr float GetFloat() noexcept
乱数の取得(float版)
Definition mgl_random_xorshift.h:54
constexpr void SetSeed(uint32_t seed) noexcept
種の設定
Definition mgl_random_xorshift.h:76
constexpr uint32_t Get() noexcept
乱数の取得
Definition mgl_random_xorshift.h:39