Files
@ r15299:e6783715e418
Branch filter:
Location: cpp/openttd-patchpack/source/src/core/random_func.cpp - annotation
r15299:e6783715e418
1.8 KiB
text/x-c
(svn r19950) -Update from WebTranslator v3.0:
french - 35 changes by ElNounch
indonesian - 28 changes by prof
irish - 58 changes by tem
french - 35 changes by ElNounch
indonesian - 28 changes by prof
irish - 58 changes by tem
r7935:d51ba3fb01a8 r7935:d51ba3fb01a8 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r9111:983de9c5a848 r7935:d51ba3fb01a8 r7935:d51ba3fb01a8 r7935:d51ba3fb01a8 r8113:7815c26d7612 r7935:d51ba3fb01a8 r8434:4d5d2dc41ce0 r8142:8414f11ec81b r8434:4d5d2dc41ce0 r7935:d51ba3fb01a8 r8434:4d5d2dc41ce0 r8434:4d5d2dc41ce0 r7935:d51ba3fb01a8 r8434:4d5d2dc41ce0 r8434:4d5d2dc41ce0 r7935:d51ba3fb01a8 r7935:d51ba3fb01a8 r15026:ba524394be83 r7935:d51ba3fb01a8 r15026:ba524394be83 r8434:4d5d2dc41ce0 r8434:4d5d2dc41ce0 r8434:4d5d2dc41ce0 r8434:4d5d2dc41ce0 r8434:4d5d2dc41ce0 r8434:4d5d2dc41ce0 r7935:d51ba3fb01a8 r7935:d51ba3fb01a8 r7935:d51ba3fb01a8 r7935:d51ba3fb01a8 r8434:4d5d2dc41ce0 r8434:4d5d2dc41ce0 r7935:d51ba3fb01a8 r7935:d51ba3fb01a8 r7935:d51ba3fb01a8 r14544:47ddf4cd89b3 r10255:0578669dfff6 r10208:ef8fcc3dc4ca r8477:5efae99a3878 r7935:d51ba3fb01a8 r7935:d51ba3fb01a8 r11967:df0600d2c7e7 r10506:87cc1a24853c r8434:4d5d2dc41ce0 r8434:4d5d2dc41ce0 r8477:5efae99a3878 r8434:4d5d2dc41ce0 r7935:d51ba3fb01a8 r15026:ba524394be83 r7935:d51ba3fb01a8 r15026:ba524394be83 r7935:d51ba3fb01a8 r8792:db826506a415 | /* $Id$ */
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @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(uint32 max)
{
return ((uint64)this->Next() * (uint64)max) >> 32;
}
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.h"
#include "../network/network_internal.h"
#include "../company_func.h"
uint32 DoRandom(int line, const char *file)
{
if (_networking && (!_network_server || (NetworkClientSocket::IsValidID(0) && NetworkClientSocket::Get(0)->status != STATUS_INACTIVE))) {
printf("Random [%d/%d] %s:%d\n", _frame_counter, (byte)_current_company, file, line);
}
return _random.Next();
}
uint32 DoRandomRange(uint32 max, int line, const char *file)
{
return ((uint64)DoRandom(line, file) * (uint64)max) >> 32;
}
#endif /* RANDOM_DEBUG */
|