openclonk/src/lib/C4Random.h

40 lines
960 B
C
Raw Normal View History

2009-05-08 13:28:41 +00:00
/*
* OpenClonk, http://www.openclonk.org
*
* Copyright (c) 1998-2000, Matthes Bender
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
2016-04-03 18:18:29 +00:00
* Copyright (c) 2013-2016, The OpenClonk Team and contributors
2009-05-08 13:28:41 +00:00
*
* Distributed under the terms of the ISC license; see accompanying file
* "COPYING" for details.
2009-05-08 13:28:41 +00:00
*
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
* See accompanying file "TRADEMARK" for details.
2009-05-08 13:28:41 +00:00
*
* To redistribute this file separately, substitute the full license texts
* for the above references.
2009-05-08 13:28:41 +00:00
*/
/* Network-safe random number generator */
2009-05-08 13:28:41 +00:00
#ifndef INC_C4Random
#define INC_C4Random
2016-04-20 18:46:55 +00:00
#include <pcg/pcg_random.hpp>
2009-05-08 13:28:41 +00:00
extern int RandomCount;
2016-04-20 18:46:55 +00:00
extern pcg32 SafeRandom;
2009-05-08 13:28:41 +00:00
2016-04-20 18:46:55 +00:00
void FixedRandom(uint64_t dwSeed);
2009-05-08 13:28:41 +00:00
2016-04-20 18:46:55 +00:00
uint32_t Random(uint32_t iRange);
2009-05-08 13:28:41 +00:00
2016-04-20 18:46:55 +00:00
inline uint32_t SeededRandom(uint64_t iSeed, uint32_t iRange)
{
if (!iRange) return 0;
2016-04-20 18:46:55 +00:00
pcg32 rng(iSeed);
return rng(iRange);
}
2009-05-08 13:28:41 +00:00
#endif // INC_C4Random