14 Commits
Author SHA1 Message Date
ephphatha c1f3dcb705 Use safer versions of random number functions instead of GenerateRnd 2023-09-19 16:52:40 +02:00
ephphatha 3bbb80d849 Introduce temporary function to advance the global rng state and discard results 2023-05-07 16:35:03 +02:00
ephphatha b98e5fcfad split logic responsible for advancing global generator state to a dedicated function
Exposing this also allows updating the engine test case to avoid peeking at the engine state after a roll, also will be useful for setting item/object seeds
2023-05-07 16:35:03 +02:00
ephphatha 08acd4aac0 Tidy up T_FitObj5 2022-09-15 23:37:42 +02:00
ephphatha 8d0afac194 Don't preserve an unreachable vanilla bug 2022-06-14 16:21:00 +02:00
ephphatha cf956aff96 Use identifiable messages when test cases fail 2022-06-14 16:21:00 +02:00
obligaron 82cea78def Apply clang-format 2021-08-11 20:52:32 +02:00
ephphatha 357f6f1dc3 Move RNG functions to their own header/source files 2021-06-27 03:09:41 -07:00
Andrew James 20190ee687 Update random number functions to avoid IB (#2226)
* Update random number functions to avoid IB

Most calls to set seed were using uint32_t already, there were a few variables which were better served by having their type changed from signed to unsigned. The one exception is ItemStruct::_iSeed. This is an identifier that also happens to be used as a seed occasionally so a comment was added documenting this exception.

Includes suggested style changes for Source/towners.h; Source/towners.cpp; Source/msg.h; Source/multi.h
2021-06-27 10:37:09 +02:00
ephphatha a6b982b39d Expand test cases to cover ShiftDistribution function
This could be isolated due to a potentially faulty implementation, the upper bound is higher than the max possible value.
2021-06-23 14:46:42 -07:00
ephphatha ac8d40458c Add tests for corner cases of the distribution functions
Hoping to add a few tests for normal operation as a sanity check. The eventual goal is to be able to split the distribution functions from the engine so they can be tested and implemented independently.
2021-06-22 12:39:04 -07:00
ephphatha a88f991746 Declare RandomTest test suite in the devilution namespace
This is recommended for GTest and is a requirement to use FRIEND_TEST (see http://google.github.io/googletest/reference/testing.html#FRIEND_TEST). If the random number generator code becomes a class with private attributes this allows us to switch to test fixtures more easily.
2021-06-22 12:39:04 -07:00
ephphatha 5b0accb13c Make it clearer when seeds are being converted from unsigned to signed 2021-06-20 16:27:06 -07:00
ephphatha 8d5b5e833b Add tests for LCG random engine
This documents the chosen LCG parameters and the default mapping function used in random number generation.

GetLCGEngineState() is a helper needed for testing because AdvanceRndSeed combines a distribution with a call to progress the engine. I'll split those eventually but this at least shows the current behaviour and should flag any bugs introduced by future changes.
2021-06-20 16:27:06 -07:00