# Random function? while looping, plz look *reward*

## Recommended Posts

Is there anyway that I can like have a value, and have it randomly add or subtract the number, 1, 2, 3, 4, 5 (randomly pick out of that set)

What I'm working with is like:

```Dim \$x1, \$y1, \$x2, \$y2

\$x1 = 81
\$y1 = 593
\$x2 = 87
\$y2 = 452
\$speed = 5

MouseClickDrag("Left", (\$x1 +- (1-5)), (\$y1 +- (1-5)), (\$x2 +- (1-5)), (\$y2 +- (1-5)), (\$speed +- (1-3)))```

Any way to make it add/subtract randomly, then make it add/subtract 1, 2, 3, 4, 5 at random? Also I would need it to loop, around, every (60,000MS +- (1,000MS-5,000MS))

If you can figure out this problem I am open to donateing for your help, AIM: o0oDakotao0o MSN: o69dakota69o@hotmail.com thanks!

##### Share on other sites

This might work for the random part. I'll let you figure out the looping.

```; General formula Random = Int(Rnd * Upperbound) + Lowerbound

MouseClickDrag("Left", (\$x1 + _Rand()), (\$y1 + _Rand()), (\$x2 + _Rand()), (\$y2 + _Rand()), (\$speed + _Rnd(1,3)))

Func _Rand();hard coded 1 to 5
Return _Rnd(1, 5)
EndFunc

Func _Rnd(\$hi, \$lo)
If Random() < 0.5 Then
Return Int(Random(\$hi)+\$lo))
Else
Return -Int(Random(\$hi)+\$lo))
Endif
EndFunc```
Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

##### Share on other sites

Free, if you ever want to donate, Jon and the website can always use it.

```Dim \$x1, \$y1, \$x2, \$y2

\$x1 = 81
\$y1 = 593
\$x2 = 87
\$y2 = 452
\$speed = 5

MouseClickDrag("Left", (\$x1 +R5()), (\$y1 +R5()), (\$x2 +R5()), (\$y2 +R5()), (\$speed +R5()))

func R5()
\$r=int(Random ( 1,6 ))
If Random() < 0.5 Then  \$r = \$r*(-1)
return \$r
endfunc```

AutoIt3, the MACGYVER Pocket Knife for computers.

##### Share on other sites

Dang Cyber ya beat me to it, but remember Random 1~5 is more like 1.00000 to 4.99999 the chance you ever see a 5 is um 1 in 100 million? I forgot the exact precision. Anyway that is why mine uses 1~6.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

##### Share on other sites

this is what i have

```Dim \$x1, \$y1, \$x2, \$x3, \$speed

\$x1 = 81
\$y1 = 593
\$x2 = 87
\$y2 = 452
\$speed = 5

MouseClickDrag("Left", \$x1 rnd(+,-) rnd(1,2,3,4,5), \$y1 rnd(+,-) rnd(1,2,3,4,5), \$x2 rnd(+,-) rnd(1,2,3,4,5), \$y2 rnd(+,-) rnd(1,2,3,4,5), \$speed rnd(+,-) rnd(1,2,3))```

what's the function for random? AIM message would help

##### Share on other sites

Random ( [[Min ,] Max] )

Random (1,5) would give back a number like 2.03342

so you want an int like this:

Int(Random(1,5))

That would never give you a 5, because Int just removes anything after the .

So you actually want int(Random(1,6)) if you want 1~5

For the second part, you just want a 50/50 chance of a negative, so

If Random() < 0.5 Then \$r = \$r*(-1)

was my way of multiplying the result by -1 50% of the time.

and my code does all your random +-(1 to 5) all in one:

```Dim \$x1, \$y1, \$x2, \$y2

\$x1 = 81
\$y1 = 593
\$x2 = 87
\$y2 = 452
\$speed = 5

MouseClickDrag("Left", (\$x1 +R5()), (\$y1 +R5()), (\$x2 +R5()), (\$y2 +R5()), (\$speed +R5()))
; I add the number that gets returned by R5(), when it is negative, adding a negative number is the same as subtracting.

func R5()
\$r=int(Random ( 1,6 )); pick 1,2,3,4,or 5
If Random() < 0.5 Then  \$r = \$r*(-1); 50% of the time make it negative
return \$r ; give the number back
endfunc```

A quick tutorial showing that random(1,5) never gets a 5.

```\$x=""
for \$i= 1 to 1000
\$x=\$x & "|"& int(Random(1,5))
if stringinstr(\$x,"5") then msgbox(1,"wow you got a 5",\$x); not going to happen
next
msgbox(1,"",\$x); here is 1000 random numbers seperated by |
exit```

help file:

Random

--------------------------------------------------------------------------------

Generates a pseudo-random float-type number.

Random ( [[Min ,]Max] )

Parameters

Min [optional] The smallest number to be generated. The default is 0.

Max [optional] The largest number to be generated. The default is 1.

Return Value

Success: Returns a pseudo-random number between Min and Max.

Failure: Returns numeric 1 and sets @error flag:

1 if argument is an array or non-numeric string

2 if Min > Max

Remarks

If only one argument is provided, then it is interpreted to be the Max.

The result will be a float in the range of Min to Max, including Min, but NOT including Max.

Related

Int, Round

Example

;Flip of coin

If Random() < 0.5 Then  ; Returns a value between 0 and 1.

Else

\$msg = "Tails. 50% Loss"

Endif

MsgBox(0,"Coin toss", \$msg )

;Roll of a die

msgBox(0,"Roll of die", "You rolled a " & Int(Random(6)+1))

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

##### Share on other sites
dude YOU ROCK THX SO MUCH:)

##### Share on other sites

How would I get that to loop every 60 seconds, like this, "Drop/Drag -> 60,000MS+-5000MS(random again) -> drag/drop, etc, etc, etc Any ideas? thanks for being so helpful

```;delay start
Opt("MouseClickDelay", 60146)
;delay end

Dim \$x1, \$y1, \$x2, \$y2

\$x1 = 81
\$y1 = 593
\$x2 = 87
\$y2 = 452
\$speed = 5

MouseClickDrag("Left", (\$x1 +R5()), (\$y1 +R5()), (\$x2 +R5()), (\$y2 +R5()), (\$speed +R5()))
; I add the number that gets returned by R5(), when it is negative, adding a negative number is the same as subtracting.

func R5()
\$r=int(Random ( 1,6 )); pick 1,2,3,4,or 5
If Random() < 0.5 Then  \$r = \$r*(-1); 50% of the time make it negative
return \$r; give the number back
endfunc```
Edited by skilzrulz

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...