# _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]

##### Share on other sites

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.

##### Share on other sites

\$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```

Live for the present,
Dream of the future,
Learn from the past.

##### 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]

## Create an account

Register a new account