19 Commits

Author SHA1 Message Date
Eugene Sandulenko
0fb25d7734
COMMON: Allow specify random seed via scummvm.ini 2023-01-02 16:12:44 +01:00
Eugene Sandulenko
41da1de090
COMMON: Sync RNG seed initialising between common and event recorder 2023-01-02 16:12:44 +01:00
Thierry Crozat
eff98b0c56 COMMON: Fix undefined behaviour in RandomSource constructor
The 'time.tm_year * 86400 * 366' line caused the result to overflow
what can be stored in an int; and signed int overflow is undefined
behaviour. The result goes into an unsigned int anyway, so now
all the intermediate computations are also done with unsigned int.
It still overflows (not on this line, but on the next one), but
that is fine as the standard guarantees that unsigned int overflow
wraps around.
2022-10-31 21:46:22 +00:00
Le Philousophe
111d259015 ALL: Add limits.h for all codebase 2022-08-22 15:38:10 +02:00
Eugene Sandulenko
abea37c9bb
ALL: Update ScummVM project license to GPLv3+ 2021-12-26 18:48:43 +01:00
TehGelly
0992fa9c3b
COMMON: Change PRNG Function to Xorshift* (#3341)
The old RNG method had non-standard periods, ranging from some seeds looping on themselves (seed = 1184201285) to some seeds having periods as low as 11 or 48, as listed in https://github.com/scummvm/scummvm/pull/3340. This is a problem even for games that run the RNG once a frame, as the possibilities for random events is greatly reduced should the initial seed be in one of these sets of small periods.

Xorshift* is a standard, fast, non-cryptographic PRNG with academic backing that has period 2^32-1 (all seeds lead to another seed except 0, which is excluded from the initial seeds).  Many different flavors are possible, as listed in the paper, but the choice implemented in this pull request uses only a single 32-bit integer as a state, like the old PRNG.

Co-authored-by: Thierry Crozat <criezy@scummvm.org>
Co-authored-by: Filippos Karapetis <bluegr@gmail.com>
2021-09-09 21:46:08 +03:00
Die4Ever
b617364f45 COMMON: improve RandomSource initial seed
This improves the range of seeds compared to using only getMillis (which
is the number of milliseconds since program start) as the seed. This was
especially an issue if you started the game directly from command line,
Steam, or GOG instead of using the ScummVM interface. Previously the
initial seed was just the load time, which can have very small variance
on a fast computer.
2021-08-28 22:55:13 +02:00
Fiodar Stryzhniou
fe274d10ba COMMON: Fix c++ header usage. 2021-08-18 18:22:55 +03:00
Aapo Vienamo
de1338787f COMMON: Fix divide by zero in getRandomNumber()
Calling RandomSource::getRandomNumber() results in divide by zero
exception when called with max = 4294967295 as max + 1 overflows to zero
and the subsequent modulus operation causes the exception.

Certain game saves in Bladerunner trigger this.
2021-08-02 13:40:11 +03:00
Vladimir Serbinenko
18626c2e96 COMMON: Add a signed variant of getRandomNumberRng.
Useful for generating negative numbers
2020-10-25 01:02:58 +02:00
Johannes Schickel
854e22b38b COMMON: Make GPL headers consistent in themselves. 2014-02-18 02:39:33 +01:00
Matthew Hoops
4a7e4e5b22 ALL: Don't use EventRecorder at all when not compiled in 2013-07-06 23:54:45 -04:00
Eugene Sandulenko
f59512c47e RECORDER: Implement Events Recorder 2013-05-17 00:18:09 +03:00
Johannes Schickel
b4d0a8ba66 JANITORIAL: Enforce "} // End of namespace" with a single space after }. 2013-01-26 19:38:02 +01:00
Max Horn
d165292234 COMMON: Remove unused RandomSource destructor, clarify comments, cleanup 2011-05-17 12:23:41 +02:00
Max Horn
fc9b8d2a71 COMMON: Remove auxillary RandomSource constructor 2011-05-17 12:17:28 +02:00
Max Horn
4cbe4ede66 COMMON: Registers RandomSources in constructor with the event recorder
This also removes the dependency of engines on the event recorder header
and API, and will make it easier to RandomSources that are not properly
registered.
2011-05-17 12:17:26 +02:00
strangerke
69b1485a22 GIT: Clean up: Suppress SVN tags, now useless 2011-05-12 01:16:22 +02:00
Max Horn
d78dba3bca COMMON: Move Common::RandomSource to common/random.*
svn-id: r48279
2010-03-18 15:07:11 +00:00