Jump to content
Sign in to follow this  
t0ddie

small help with random

Recommended Posts

$flash = random(0,1)

i want the value of flash to be "0" or "1" and this wasnt working. i put a message box in there, and its splitting it into decimals.

how do i make it just whole numbers? so i get one or zero, and not some decimal in between them like

0.687234987234

thanks

T0ddie


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

Untested, but should work :

$nr = Random(0,1)
$nr = Round($nr,0)

MsgBox(64,"0/1",$nr)

PS!

It`s always smart to check the "Related"-functions when wondering

about a function. Under Random you would have found Round...

Share this post


Link to post
Share on other sites

If you have to calc a single number it does not change, but otherwise it is much better using Int() than Round() since it is much faster.

I made a small func, it may be useful often.

MsgBox(0,'',_RandomInt(0,1))

Func _RandomInt($iMin,$iMax)
   If $iMax < $iMin Then Return Int($iMin)
   
   Return Int(Random($iMin,$iMax + 1))
EndFunc
Edited by ezzetabi

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...