Jump to content

_random .... Udf


Recommended Posts

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

  • Moderators

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
Wow, 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 $leave1

For $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 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

  • Developers

$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

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...