From 02b1f7e07827f6b7701a7730242016ff0378dfdd Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Tue, 18 Jul 2017 18:17:39 -0230 Subject: [PATCH] Make Random::next() const, since logically it should be. The fact that it updates an internal variable is an implementation detail that shouldn't be exposed outside the class. --- src/emucore/Random.hxx | 8 ++++++-- src/emucore/System.hxx | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/emucore/Random.hxx b/src/emucore/Random.hxx index 59000abc2..2170a599c 100644 --- a/src/emucore/Random.hxx +++ b/src/emucore/Random.hxx @@ -52,7 +52,7 @@ class Random @return A random number */ - uInt32 next() + uInt32 next() const { return (myValue = (myValue * 2416 + 374441) % 1771875); } @@ -62,7 +62,11 @@ class Random const OSystem& myOSystem; // Indicates the next random number - uInt32 myValue; + // We make this mutable, since it's not immediately obvious that + // calling next() should change internal state (ie, the *logical* + // state of the object shouldn't change just by asking for another + // random number) + mutable uInt32 myValue; private: // Following constructors and assignment operators not supported diff --git a/src/emucore/System.hxx b/src/emucore/System.hxx index 2f4fde0dc..d62f36fec 100644 --- a/src/emucore/System.hxx +++ b/src/emucore/System.hxx @@ -182,7 +182,7 @@ class System : public Serializable @param hmask The bits which should always be driven high @return The data bus state */ - uInt8 getDataBusState(uInt8 zmask, uInt8 hmask = 0x00) + uInt8 getDataBusState(uInt8 zmask, uInt8 hmask = 0x00) const { // For the pins that are floating, randomly decide which are high or low // Otherwise, they're specifically driven high