… | |
… | |
51 | state [1] = state [0] * 69069U; if (state [0] < 8U) state [0] += 8U; |
51 | state [1] = state [0] * 69069U; if (state [0] < 8U) state [0] += 8U; |
52 | state [2] = state [1] * 69069U; if (state [0] < 16U) state [0] += 16U; |
52 | state [2] = state [1] * 69069U; if (state [0] < 16U) state [0] += 16U; |
53 | state [3] = state [2] * 69069U; if (state [0] < 128U) state [0] += 128U; |
53 | state [3] = state [2] * 69069U; if (state [0] < 128U) state [0] += 128U; |
54 | |
54 | |
55 | for (int i = 11; --i; ) |
55 | for (int i = 11; --i; ) |
56 | operator ()(); |
56 | next (); |
57 | } |
57 | } |
58 | |
58 | |
59 | uint32_t |
59 | uint32_t |
60 | tausworthe_random_generator::next () |
60 | tausworthe_random_generator::next () |
61 | { |
61 | { |
… | |
… | |
65 | state [3] = ((state [3] & 0xFFFFFF80U) << 13U) ^ (((state [3] << 3U) ^ state [3]) >> 12U); |
65 | state [3] = ((state [3] & 0xFFFFFF80U) << 13U) ^ (((state [3] << 3U) ^ state [3]) >> 12U); |
66 | |
66 | |
67 | return state [0] ^ state [1] ^ state [2] ^ state [3]; |
67 | return state [0] ^ state [1] ^ state [2] ^ state [3]; |
68 | } |
68 | } |
69 | |
69 | |
|
|
70 | template<class generator> |
70 | uint32_t |
71 | uint32_t |
71 | tausworthe_random_generator::get_range (uint32_t num) |
72 | random_number_generator<generator>::get_range (uint32_t num) |
72 | { |
73 | { |
73 | return (next () * (uint64_t)num) >> 32U; |
74 | return (this->next () * (uint64_t)num) >> 32U; |
74 | } |
75 | } |
75 | |
76 | |
76 | // return a number within (min .. max) |
77 | // return a number within (min .. max) |
|
|
78 | template<class generator> |
77 | int |
79 | int |
78 | tausworthe_random_generator::get_range (int r_min, int r_max) |
80 | random_number_generator<generator>::get_range (int r_min, int r_max) |
79 | { |
81 | { |
80 | return r_min + get_range (max (r_max - r_min + 1, 0)); |
82 | return r_min + get_range (max (r_max - r_min + 1, 0)); |
81 | } |
83 | } |
|
|
84 | |
|
|
85 | template struct random_number_generator<tausworthe_random_generator>; |
|
|
86 | template struct random_number_generator<xorshift_random_generator>; |
82 | |
87 | |
83 | /* |
88 | /* |
84 | * The random functions here take luck into account when rolling random |
89 | * The random functions here take luck into account when rolling random |
85 | * dice or numbers. This function has less of an impact the larger the |
90 | * dice or numbers. This function has less of an impact the larger the |
86 | * difference becomes in the random numbers. IE, the effect is lessened |
91 | * difference becomes in the random numbers. IE, the effect is lessened |