OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: bigcheese on 28 Oct 2003, 19:31:28
-
Right,
You know when you create a random number and it comes up with all that crazy decimal point crap that no one could give a monkeys S%$T about, (god forbid anyone actually has got a monkeys S%$T to give).
Example
hint format["Random Number = %1",(Random 180)]
... and it comes up with 59.235 or something like that,
well how do you cut out all that crap and round it up to 1 solid number?
Any help will be GREATLY appreciated,
(But if you even think about double-crossing me, there'll be a flaming monkeys crap winging its way to your door.)
-
To cut away the decimal part, use the mod command like this:
_random = random 180
_random = _random - (_random mod 1)
hint format["Random Number = %1",_random]
Be aware though, that the final number will range between 0,...,179
(and not 180), due to simply cutting the odd part.
-
thanks for the info Spinor
You Rock
But after carefull consideration i have decided to send you a monkeys crap after all,
(Because there pilling up round here)
If youd mind setting fire to it when it gets there though, and prtending it arrived like that, :wow:
cheers mate
-
There is a small chance that the random number will be exactly 180.
But to eliminate it completely, write
Random 180.9
Then you get a number between 0 and 180
-
There is a small chance that the random number will be exactly 180.Are you positive about that? I have never been sure if
random X
includes or excludes X, or mathematically speaking if its [0,X] or [0,X).
But to eliminate it completely, write
Random 180.9
Then you get a number between 0 and 180 But then the chance to get 180 would be 10% less than any other number ;)
Using
random 180.999999999
would be even better ;D
-
Or, you could use a function that only returns a random integer within a specified range. Much like the one I wrote that you can find here:
http://www.ofpec.com/editors/funcref.php?filter_func=42 (http://www.ofpec.com/editors/funcref.php?filter_func=42)