ClientStateError(std::string s): BaseException(s) {}
};
+class PrngException : public BaseException {
+public:
+ PrngException(std::string s): BaseException(s) {}
+};
+
/*
Some "old-style" interrupts:
*/
s32 PcgRandom::range(s32 min, s32 max)
{
- assert(max >= min);
+ if (max < min)
+ throw PrngException("Invalid range (max < min)");
+
u32 bound = max - min + 1;
return range(bound) + min;
}
#ifndef NOISE_HEADER
#define NOISE_HEADER
-#include "debug.h"
#include "irr_v3d.h"
+#include "exceptions.h"
#include "util/string.h"
extern FlagDesc flagdesc_noiseparams[];
inline int range(int min, int max)
{
- assert(max >= min);
+ if (max < min)
+ throw PrngException("Invalid range (max < min)");
/*
Here, we ensure the range is not too large relative to RANDOM_MAX,
as otherwise the effects of bias would become noticable. Unlike
PcgRandom, we cannot modify this RNG's range as it would change the
output of this RNG for reverse compatibility.
*/
- assert((u32)(max - min) <= (RANDOM_RANGE + 1) / 10);
+ if ((u32)(max - min) > (RANDOM_RANGE + 1) / 10)
+ throw PrngException("Range too large");
return (next() % (max - min + 1)) + min;
}