Home   Help Search Login Register  

Author Topic: Random Numbers  (Read 568 times)

0 Members and 1 Guest are viewing this topic.

bigcheese

  • Guest
Random Numbers
« 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.)

Offline Spinor

  • Members
  • *
  • I'm a llama!
    • The chain of command
Re:Random Numbers
« Reply #1 on: 28 Oct 2003, 19:39:42 »
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.

bigcheese

  • Guest
Re:Random Numbers
« Reply #2 on: 28 Oct 2003, 20:03:46 »
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

Oakstar

  • Guest
Re:Random Numbers
« Reply #3 on: 30 Oct 2003, 11:13:59 »
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

Offline Spinor

  • Members
  • *
  • I'm a llama!
    • The chain of command
Re:Random Numbers
« Reply #4 on: 30 Oct 2003, 12:23:40 »
Code: [Select]
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).

Code: [Select]
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

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Random Numbers
« Reply #5 on: 31 Oct 2003, 06:37:44 »
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
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!