ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/rng.C
(Generate patch)

Comparing deliantra/server/common/rng.C (file contents):
Revision 1.3 by root, Sat Apr 23 04:56:46 2011 UTC vs.
Revision 1.9 by root, Sat Nov 17 23:40:00 2018 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 6 *
6 * Deliantra is free software: you can redistribute it and/or modify it under 7 * Deliantra is free software: you can redistribute it and/or modify it under
7 * the terms of the Affero GNU General Public License as published by the 8 * the terms of the Affero GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your 9 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version. 10 * option) any later version.
10 * 11 *
11 * This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 15 * GNU General Public License for more details.
15 * 16 *
16 * You should have received a copy of the Affero GNU General Public License 17 * You should have received a copy of the Affero GNU General Public License
17 * and the GNU General Public License along with this program. If not, see 18 * and the GNU General Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>. 19 * <http://www.gnu.org/licenses/>.
19 * 20 *
20 * The authors can be reached via e-mail to <support@deliantra.net> 21 * The authors can be reached via e-mail to <support@deliantra.net>
21 */ 22 */
22 23
23#include <cmath> 24#include <cmath>
24 25
25#include <global.h> 26#include <global.h>
26 27
27rand_gen rndm, rmg_rndm; 28rand_gen rndm, rmg_rndm;
28 29
29void noinline 30ecb_noinline void
30tausworthe_rng::seed (uint32_t seed) 31tausworthe_rng::seed (uint32_t seed)
31{ 32{
32 state [0] = seed * 69069U; if (state [0] < 2U) state [0] += 2U; 33 state [0] = seed * 69069U; if (state [0] < 2U) state [0] += 2U;
33 state [1] = state [0] * 69069U; if (state [1] < 8U) state [1] += 8U; 34 state [1] = state [0] * 69069U; if (state [1] < 8U) state [1] += 8U;
34 state [2] = state [1] * 69069U; if (state [2] < 16U) state [2] += 16U; 35 state [2] = state [1] * 69069U; if (state [2] < 16U) state [2] += 16U;
47 state [3] = ((state [3] & 0xFFFFFF80U) << 13U) ^ (((state [3] << 3U) ^ state [3]) >> 12U); 48 state [3] = ((state [3] & 0xFFFFFF80U) << 13U) ^ (((state [3] << 3U) ^ state [3]) >> 12U);
48 49
49 return state [0] ^ state [1] ^ state [2] ^ state [3]; 50 return state [0] ^ state [1] ^ state [2] ^ state [3];
50} 51}
51 52
52void noinline 53ecb_noinline void
53r250521_rng::seed (uint32_t seed) 54r250521_rng::seed (uint32_t seed)
54{ 55{
55 xorshift_rng rng; 56 xorshift_rng rng;
56 57
57 rng.seed (seed); 58 rng.seed (seed);
72{ 73{
73 return (this->next () * (uint64_t)num) >> 32U; 74 return (this->next () * (uint64_t)num) >> 32U;
74} 75}
75 76
76template<class generator> 77template<class generator>
77uint32_t noinline 78ecb_noinline uint32_t
78random_number_generator<generator>::get_u32 () 79random_number_generator<generator>::get_u32 ()
79{ 80{
80 return generator::next (); 81 return generator::next ();
81} 82}
82 83
83template<class generator> 84template<class generator>
84uint64_t noinline 85ecb_noinline uint64_t
85random_number_generator<generator>::get_u64 () 86random_number_generator<generator>::get_u64 ()
86{ 87{
87 return (uint64_t (get_u32 ()) << 32U) | get_u32 (); 88 return (uint64_t (get_u32 ()) << 32U) | get_u32 ();
88} 89}
89 90
90template<class generator> 91template<class generator>
91float noinline 92ecb_noinline float
92random_number_generator<generator>::get_float () 93random_number_generator<generator>::get_float ()
93{ 94{
94 return this->next () / (float)0x100000000ULL; 95 return this->next () / (float)0x100000000ULL;
95} 96}
96 97
97template<class generator> 98template<class generator>
98double noinline 99ecb_noinline double
99random_number_generator<generator>::get_double () 100random_number_generator<generator>::get_double ()
100{ 101{
101 return this->next () / (double)0x100000000ULL; 102 return this->next () / (double)0x100000000ULL;
102} 103}
103 104
104// return a number within (min .. max) 105// return a number within (min .. max)
105template<class generator> 106template<class generator>
106int 107int
107random_number_generator<generator>::get_range (int r_min, int r_max) 108random_number_generator<generator>::get_range (int r_min, int r_max)
108{ 109{
109 return r_min + get_range (max (r_max - r_min + 1, 0)); 110 return r_min + get_range (max (r_max - r_min + 1, 0));
110} 111}
111 112

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines