[QUOTE=Somebody] I use 5-Random(11) for cases like this.[/QUOTE]

And it is good that you do so, because random(integer) returns floor(random), or in other words:

random(10) produces a number greater than 0 and less than 10 (e.g. 0.024 or 9.8453) and returns it rounded down to the nearest integer (0.024 will be returned as 0, 9.8453 as 9)

As a result, random(10) will return one of 10 numbers ranging from 0 to 9.

-5 + random(10) would be -5 + [0, 9] => [-5, 4]

random(10) - 5 would be [0, 9] - 5 => [-5, 4]

to reach the full range of [-5, 5] (which is 11 numbers) you need random(11) (which returns in a range of 11 numbers from 0 to 10):

5 - random(11) would be 5 - [0, 10] => [5, -5]

random(11) - 5 would be [0, 10] - 5 => [-5, 5]

-5 + random(11) would be -5 + [0, 10] => [-5, 5]

The order doesn't make a difference, so use whatever looks good to you, just make sure the full range is covered

tulamide2011-10-04 00:29:01