Files @ r10412:5923d8bb7636
Branch filter:

Location: cpp/openttd-patchpack/source/src/core/random_func.cpp

translators
(svn r14665) -Update: WebTranslator2 update to 2008-12-09 18:44:40
arabic_egypt - 301 fixed by khaloofah (301)
esperanto - 64 fixed, 2 changed by alekcxjo (66)
hebrew - 430 fixed by moshe (430)
hungarian - 10 changed by alyr (9), oklmernok (1)
indonesian - 49 fixed, 4 changed by fanioz (40), anansboga (13)
lithuanian - 5 fixed by Enternald (5)
portuguese - 6 fixed by SnowFlake (6)
thai - 333 fixed by vetbook (333)
/* $Id$ */

/** @file random_func.cpp Implementation of the pseudo random generator. */

#include "../stdafx.h"
#include "random_func.hpp"
#include "bitmath_func.hpp"

Randomizer _random, _interactive_random;

uint32 Randomizer::Next()
{
	const uint32 s = this->state[0];
	const uint32 t = this->state[1];

	this->state[0] = s + ROR(t ^ 0x1234567F, 7) + 1;
	return this->state[1] = ROR(s, 3) - 1;
}

uint32 Randomizer::Next(uint16 max)
{
	return GB(this->Next(), 0, 16) * max >> 16;
}

void Randomizer::SetSeed(uint32 seed)
{
	this->state[0] = seed;
	this->state[1] = seed;
}

void SetRandomSeed(uint32 seed)
{
	_random.SetSeed(seed);
	_interactive_random.SetSeed(seed * 0x1234567);
}

#ifdef RANDOM_DEBUG
#include "../network/network_internal.h"
#include "../variables.h" /* _frame_counter */
#include "../company_func.h"

uint32 DoRandom(int line, const char *file)
{
	if (_networking && (DEREF_CLIENT(0)->status != STATUS_INACTIVE || !_network_server)) {
		printf("Random [%d/%d] %s:%d\n",_frame_counter, (byte)_current_company, file, line);
	}

	return _random.Next();
}

uint DoRandomRange(uint max, int line, const char *file)
{
	return GB(DoRandom(line, file), 0, 16) * max >> 16;
}
#endif /* RANDOM_DEBUG */