Daniel W. Posted May 5, 2006 Share Posted May 5, 2006 Hi, i wanted to write a Function that makes Random( min , max) and if the return is a given number it does Random(min,max) again. Here is the Code and i dont know why it doesnt work Dim $min Dim $max Dim $leave1, $leave2, $leave3, $leave4, $i, $k For $h = 1 to 5 Step 1 _Random( 1, 5, 3) MsgBox(0, "", $k) Next Func _Random( $min, $max, $leave1) $i = Random( $min, $max, 1) If $i = $leave1 Then $i = Random( $min, $max, 1) $i = $k Else $i = $k EndIf EndFunc --------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 5, 2006 Moderators Share Posted May 5, 2006 (edited) Hi, i wanted to write a Function that makes Random( min , max) and if the return is a given number it does Random(min,max) again. Here is the Code and i dont know why it doesnt work Dim $min Dim $max Dim $leave1, $leave2, $leave3, $leave4, $i, $k For $h = 1 to 5 Step 1 _Random( 1, 5, 3) MsgBox(0, "", $k) Next Func _Random( $min, $max, $leave1) $i = Random( $min, $max, 1) If $i = $leave1 Then $i = Random( $min, $max, 1) $i = $k Else $i = $k EndIf EndFuncWow, totally confused on what you actually want. The example you've given, never makes $k anything other than $k which means $i always = $k? Edit: If you don't want to ever show the specific number set for $leave1For $h = 1 to 5 $k = _Random( 1, 5, 3) MsgBox(0, "", $k) Next Func _Random( $min, $max, $leave1) Do $i = Random($min, $max, 1) Until $i <> $leave1 Return $i EndFunc Edit2: Or use Jdeb's example :"> Edited May 5, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Developers Jos Posted May 5, 2006 Developers Share Posted May 5, 2006 $k is never set... I would do something like if i understand you correctly: Dim $min Dim $max Dim $leave1, $leave2, $leave3, $leave4, $i, $k For $h = 1 to 5 Step 1 $k = _Random( 1, 5, 3) MsgBox(0, "", $k) Next Func _Random( $min, $max, $leave1) $i = Random( $min, $max, 1) While $i = $leave1 $i = Random( $min, $max, 1) WEnd Return $i EndFunc SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Daniel W. Posted May 5, 2006 Author Share Posted May 5, 2006 Ok thank you $k was from another try i did before i posted --------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote] 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