--- deliantra/server/include/rng.h 2012/10/29 23:55:54 1.12 +++ deliantra/server/include/rng.h 2018/12/05 21:18:37 1.16 @@ -1,7 +1,8 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team + * Copyright (©) 2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * * Deliantra is free software: you can redistribute it and/or modify it under * the terms of the Affero GNU General Public License as published by the @@ -23,7 +24,7 @@ #ifndef RNG_H__ #define RNG_H__ -#include +#include "ecb.h" typedef uint32_t seed_t; // overkill @@ -172,15 +173,15 @@ // uniform distribution, [0 .. num - 1] uint32_t operator ()(uint32_t num) { - return !is_constant (num) ? get_range (num) // non-constant - : num & (num - 1) ? (this->next () * (uint64_t)num) >> 32U // constant, non-power-of-two - : this->next () & (num - 1); // constant, power-of-two + return !ecb_is_constant (num) ? get_range (num) // non-constant + : num & (num - 1) ? (this->next () * (uint64_t)num) >> 32U // constant, non-power-of-two + : this->next () & (num - 1); // constant, power-of-two } // return a number within the closed interval [min .. max], max can be >, < or == min. int operator () (int r_min, int r_max) { - return is_constant (r_min <= r_max) && r_min <= r_max + return ecb_is_constant (r_min <= r_max) && r_min <= r_max ? r_min + operator ()(r_max - r_min + 1) : get_range (r_min, r_max); }