primeval Posted January 20, 2011 Share Posted January 20, 2011 Help me to get compact and correct script. Here what i got: Dim $i[4] $i[0] = 0 $i[1] = 16 $i[2] = 34 $i[3] = 50 $rnd = Radnom(1, 100, 1) ;i need to make choise based on $i precent from random number, how to? have no idea:( Sorry for my english. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 20, 2011 Moderators Share Posted January 20, 2011 Hi, Primeval and welcome to the Forums. Your code works, you've simply mispelled Random. The snippet below shows me the random number just fine. Dim $i[4] $i[0] = 0 $i[1] = 16 $i[2] = 34 $i[3] = 50 $rnd = Random(1, 100, 1) MsgBox(0, "", $rnd) "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
iamtheky Posted January 20, 2011 Share Posted January 20, 2011 this will only return items from your array. Global $rnd Dim $i[4] $i[0] = 0 $i[1] = 16 $i[2] = 34 $i[3] = 50 _rando() while 1 for $k = 0 to ubound($i) - 1 If $rnd = $i[$k] Then msgbox (0, '' , $i[$k]) _rando () else _rando() endif Next WEnd func _rando () $rnd = Random(0, 100, 1) endfunc ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
primeval Posted January 20, 2011 Author Share Posted January 20, 2011 (edited) Thanks for reply, but, i try to explain what i whant to do. Dim $i[4], $choise ;random precents may be any $i[0] = 16 $i[1] = 0 $i[2] = 34 $i[3] = 50 $rnd = Random(1, 100, 1) ;i need to make choise based on $i precent from random number, how to? have no idea:( Select Case $rnd <= $i[0] $choise = 0 Case $rnd <= $i[0] + $i[1] $choise = 1 Case $rnd <= $i[0] + $i[1] + $i[2] $choise = 2 Case $rnd <= $i[0] + $i[1] + $i[2] + $i[3] $choise = 3 EndSelect MsgBox(0,0,"Random was:" & $rnd & " Choise:" & $choise) Here, but i gues there is a way to make it more compact or somesing? if yes will thanksfull for any way to do it:) Thanks for replays anyway. Edited January 20, 2011 by primeval Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now