File diff r18781:e1de9a06f7cd → r18782:6453522c2154
src/core/random_func.hpp
Show inline comments
 
@@ -78,29 +78,29 @@ void SetRandomSeed(uint32 seed);
 
		#define Random() DoRandom(__LINE__, __FILE__)
 
	#endif
 
	uint32 DoRandom(int line, const char *file);
 
	#define RandomRange(max) DoRandomRange(max, __LINE__, __FILE__)
 
	uint32 DoRandomRange(uint32 max, int line, const char *file);
 
#else
 
	static FORCEINLINE uint32 Random()
 
	static inline uint32 Random()
 
	{
 
		return _random.Next();
 
	}
 

	
 
	static FORCEINLINE uint32 RandomRange(uint32 max)
 
	static inline uint32 RandomRange(uint32 max)
 
	{
 
		return _random.Next(max);
 
	}
 
#endif
 

	
 
static FORCEINLINE uint32 InteractiveRandom()
 
static inline uint32 InteractiveRandom()
 
{
 
	return _interactive_random.Next();
 
}
 

	
 
static FORCEINLINE uint32 InteractiveRandomRange(uint32 max)
 
static inline uint32 InteractiveRandomRange(uint32 max)
 
{
 
	return _interactive_random.Next(max);
 
}
 

	
 
/**
 
 * Checks if a given randomize-number is below a given probability.
 
@@ -114,13 +114,13 @@ static FORCEINLINE uint32 InteractiveRan
 
 *
 
 * @param a The numerator of the fraction
 
 * @param b The denominator of the fraction, must of course not be null
 
 * @param r The given randomize-number
 
 * @return True if the probability given by r is less or equal to (a/b)
 
 */
 
static FORCEINLINE bool Chance16I(const uint a, const uint b, const uint32 r)
 
static inline bool Chance16I(const uint a, const uint b, const uint32 r)
 
{
 
	assert(b != 0);
 
	return (((uint16)r * b + b / 2) >> 16) < a;
 
}
 

	
 
/**
 
@@ -133,13 +133,13 @@ static FORCEINLINE bool Chance16I(const 
 
 * @param b The denominator of the fraction
 
 * @return True with (a/b) probability
 
 */
 
#ifdef RANDOM_DEBUG
 
	#define Chance16(a, b) Chance16I(a, b, DoRandom(__LINE__, __FILE__))
 
#else
 
static FORCEINLINE bool Chance16(const uint a, const uint b)
 
static inline bool Chance16(const uint a, const uint b)
 
{
 
	return Chance16I(a, b, Random());
 
}
 
#endif /* RANDOM_DEBUG */
 

	
 
/**
 
@@ -157,13 +157,13 @@ static FORCEINLINE bool Chance16(const u
 
 * @param r The variable to save the randomize-number from Random()
 
 * @return True in (a/b) percent
 
 */
 
#ifdef RANDOM_DEBUG
 
	#define Chance16R(a, b, r) (r = DoRandom(__LINE__, __FILE__), Chance16I(a, b, r))
 
#else
 
static FORCEINLINE bool Chance16R(const uint a, const uint b, uint32 &r)
 
static inline bool Chance16R(const uint a, const uint b, uint32 &r)
 
{
 
	r = Random();
 
	return Chance16I(a, b, r);
 
}
 
#endif /* RANDOM_DEBUG */