File diff r15025:2d23afc43d78 → r15026:ba524394be83
src/core/random_func.hpp
Show inline comments
 
@@ -39,25 +39,25 @@ struct Randomizer {
 

	
 
	/**
 
	 * Generate the next pseudo random number
 
	 * @return the random number
 
	 */
 
	uint32 Next();
 

	
 
	/**
 
	 * Generate the next pseudo random number scaled to max
 
	 * @param max the maximum value of the returned random number
 
	 * @return the random number
 
	 */
 
	uint32 Next(uint16 max);
 
	uint32 Next(uint32 max);
 

	
 
	/**
 
	 * (Re)set the state of the random number generator.
 
	 * @param seed the new state
 
	 */
 
	void SetSeed(uint32 seed);
 
};
 
extern Randomizer _random; ///< Random used in the game state calculations
 
extern Randomizer _interactive_random; ///< Random used every else where is does not (directly) influence the game state
 

	
 
/** Stores the state of all random number generators */
 
struct SavedRandomSeeds {
 
@@ -83,44 +83,43 @@ static inline void RestoreRandomSeeds(co
 
	_interactive_random = storage.interactive_random;
 
}
 

	
 
void SetRandomSeed(uint32 seed);
 
#ifdef RANDOM_DEBUG
 
	#ifdef __APPLE__
 
		#define OTTD_Random() DoRandom(__LINE__, __FILE__)
 
	#else
 
		#define Random() DoRandom(__LINE__, __FILE__)
 
	#endif
 
	uint32 DoRandom(int line, const char *file);
 
	#define RandomRange(max) DoRandomRange(max, __LINE__, __FILE__)
 
	uint DoRandomRange(uint max, int line, const char *file);
 
	uint32 DoRandomRange(uint32 max, int line, const char *file);
 
#else
 
	static FORCEINLINE uint32 Random()
 
	{
 
		return _random.Next();
 
	}
 

	
 
	static FORCEINLINE uint32 RandomRange(uint max)
 
	static FORCEINLINE uint32 RandomRange(uint32 max)
 
	{
 
		assert(max <= UINT16_MAX);
 
		return _random.Next(max);
 
	}
 
#endif
 

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

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

	
 
/**
 
 * Checks if a given randomize-number is below a given probability.
 
 *
 
 * This function is used to check if the given probability by the fraction of (a/b)
 
 * is greater than low 16 bits of the given randomize-number r.
 
 *
 
 * Do not use this function twice on the same random 16 bits as it will yield
 
 * the same result. One can use a random number for two calls to Chance16I,