The compiler returned an error when trying to perform Rand(0), with a sqrt complaint; which may mean that Rand in Bison uses square roots to determine its randomising calculations; in which case, negative integers would be a rather large problem. (i.e. Imaginary, irrational numbers, like i.)
In the event that Rand doesn't permit negative vales as arguments (especially as zscript.txt states 'The return value is undefined if maxvalue is 0 or negative.'), in ZC, or in another compiler, here are two functions that should return results. The first, negRand produces a result from a negative value, to a positive value.
The second, negativeRand, produces a result between two negative values.
If these aren't necessary, then ignore this; bit I figured it'd be best to share them, as (at the least) they're creative mathematical functions, and NegativeRand may be useful in some applications where you only want irrational numbers as results.
I did some basic logistical analysis, with spreads of numbers, and they should produce the desired results with basic mathematics.
//Produces a Rand from a negative integer, to a positive integer. //The result may be '0'. //Use positive numbers as arguments. // Usage: negRand(20, 10) produces a rand from -20 to +10. int negRand(int neg, int pos){ int sum = (pos+neg); int value = Rand(sum); int shift = neg; int total = ( value - shift ); return total; } //Produces a random negative number, from -min to -max. //Enter the arguments as positive numbers: // NegativeRand(20,10) produces a result from -20 to -10 int NegativeRand(int lowest, int highest){ int value = Rand(min,max); int shift = (0 - value - value); int total = value = shift; return total; } //Produces a floating point rand from negative value, to positive value. float negRandf(float neg, float pos){ float sum = (pos+neg); float value = Rand(sum); float shift = neg; float total = ( value - shift ); return total; } //Produces a floating point value as a negative number. float NegativeRandf(float lowest, float highest){ float value = Randf(min,max); float shift = (0 - value - value); float total = value = shift; return total; } //Produces a negative integer between minValue and 0. int nRand(int minValue){ int value = Rand(minValue); int shift = (0 - value - value); int total = value = shift; return total; }
Edited by ZoriaRPG, 01 September 2014 - 11:13 PM.