Sign in to follow this  
Followers 0
frew

How to store random values for reuse?

12 posts in this topic

Hello,

I'm trying to figure out how to save a randomly generated set of mouse clicks for later reuse.

$y = 428
$x = Random(63, 260, 1)
While 1
    MouseClick("left", $x, $y, 1, 0)
    $x = $x + Random(12, 96, 1)
    If $x > 440 Then ExitLoop
WEnd

It generates a random pattern of clicks along the x axis.

But now I wish to save the pattern of randomly generated clicks so I can use it again later.

I'm trying to find a way to store each of the incremented values of x into separate new variables.

Thanks for any ideas on what may be the best way to do this.

frew

Share this post


Link to post
Share on other sites



frew,

How about an array? ;-)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

How about an array?

Thanks Melba23.

Yes I was thinking I may need to use arrays, but I'm not familiar with how to use them for something like this yet. I guess I'll experiment with them now.

I was hoping for a simple little code example that would just grab the incremented x values so I could place them into a small series of MouseClicks.

Thanks for the idea. I'll check into arrays some more now.

frew

Share this post


Link to post
Share on other sites

Thanks Melba23.

Yes I was thinking I may need to use arrays, but I'm not familiar with how to use them for something like this yet. I guess I'll experiment with them now.

I was hoping for a simple little code example that would just grab the incremented x values so I could place them into a small series of MouseClicks.

Thanks for the idea. I'll check into arrays some more now.

frew

http://www.autoitscript.com/wiki/Arrays

[center]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.[/center]

Share this post


Link to post
Share on other sites

frew,

Do read the link in SmOke_N's post. Arrays are a fundamental part of programming. They are not difficult to understand, but can catch you out if you are not careful - like most things! ;-)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Looks like arrays is the way to go then.

I tried stepping away from my computer...then restarting my computer, and I still don't see how to do it.

Just kidding, thanks for the point in the right direction, and for the link to the Wiki about arrays.

When I figure out the solution to this coding challenge I'll post what works. Now to study arrays a bit.

Thank you,

frew

Share this post


Link to post
Share on other sites

Until I can figure out how to use arrays well, is anybody interested in showing me how to get the following results with a loop and perhaps and array?

I could build a big scripts like this one, and it would work, but I think there is a better way with looping and an array (or maybe not an array yet, but perhaps just with other coding idea I haven't thought of yet).

Imagine if I had many $x values, not just the 4 below...that's where the loops and array may come in handy.

$x = Random(1, 5, 1)
$x1 = $x
MsgBox(0, 'first $x', $x, 2)

$x = $x + Random(1, 3, 1)
$x2 = $x
MsgBox(0, 'second $x', $x, 2)

$x = $x + Random(1, 3, 1)
$x3 = $x
MsgBox(0, 'third $x', $x, 2)

$x = $x + Random(1, 3, 1)
$x4 = $x
MsgBox(0, 'fourth $x', $x, 2)

For $i = 1 To 2
_RepeatPattern_1()
Next

Func _RepeatPattern_1();the randomly generated pattern above is now available for reuse
MsgBox(0, '$x1', $x1, 2)
MsgBox(0, '$x2', $x2, 2)
MsgBox(0, '$x3', $x3, 2)
MsgBox(0, '$x4', $x4, 2)
EndFunc

Thanks for any ideas.

frew

Share this post


Link to post
Share on other sites

Global $a_x[5] = [0, Random(1, 5, 1)]
; Global $a_x[5] ... We can play with elements 0 through 4 of that (5 being the index), We're going to start usage at index 1 not 0 though.
Global $i_add = $a_x[1] ; Which is the Random(1, 5, 1)
; We now are going to start at the 2nd element to the end of the array elements (UBound(array) - 1) gives us that.
For $i = 2 To UBound($a_x) - 1
    $i_add += Random(1, 3, 1)
    $a_x[$i] = $i_add
Next
; We've now filled our array

; No idea why you're calling that function twice, but I'll go along with it
For $i = 1 To 2
    _RepeatPattern_1()
Next

Func _RepeatPattern_1()
    For $i = 1 To UBound($a_x) - 1
        MsgBox(64, "Info", "$a_x[" & $i & "] = " & $a_x[$i])
    Next
EndFunc


[center]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.[/center]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Maybe..

#include <array.au3> ; for display only

Global $x[5]

For $i = 1 To UBound($x) - 1
    $x[$i] = Random(1, 5, 1)
Next

For $i = 1 To 2
    _RepeatPattern_1($x)
Next

Func _RepeatPattern_1(ByRef $array)
    MsgBox(4096, '$x1', $array[1], 2)
    MsgBox(4096, '$x2', $array[2], 2)
    MsgBox(4096, '$x3', $array[3], 2)
    MsgBox(4096, '$x4', $array[4], 2)
EndFunc   ;==>_RepeatPattern_1

_ArrayDisplay($x)

8)

EDIT ...Just a little slow :)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

There is a much easier way to do this, use SRandom() to seed Random with a constant value before generating your set of random values and Random() will return the same set of random values each time.

$RandSeed = 3.5 ; chane this value to generate a different set of randome values

SRandom ($RandSeed)
For $i = 1 To 10 Step 1
    $RandVal = Random(0,700,1)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $RandVal = ' & $RandVal & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
Next

SRandom ($RandSeed)
For $i = 1 To 10 Step 1
    $RandVal = Random(0,700,1)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $RandVal = ' & $RandVal & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
Next

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

SmOke_N, Valuater, Bowmore,

I greatly thank all of you for your kind help and examples.

I'll need time to study these things, and then I'll post back to let you know how it goes.

I think the Seeded Random way might do what I need, but the arrays is a tool that I need to get to know better.

I have a music program where I can input notes randomly, but if it's a random pattern I like, I like to be able to duplicate the pattern. With quick tests it looks like the arrays ways will do it. And the Seeded Random looks like it will certainly do it too.

Thanks so much for the help with this. Now I study what you've presented, and I do testing.

Thanks again,

frew

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Cool, this does exactly what I want.

$y = 428
SRandom (12345)
For $i = 1 To 4 Step 1
    $x = Random(63,400,1)
    MsgBox(0, '', $x, 1)
    MouseClick("left", $x, $y, 1, 0)
Next

Thanks so much Bowmore for pointing me to SRandom.

Basically I want to generate a set of mouse clicks that are placed randomly on the x axis, and then be able to take that randomly generated set of mouse clicks and use that set over and over if I want to. SRandom is the easiest solution.

I'm still going over the array solutions too though, because they are very helpful code examples for me to learn from.

Thanks again to all for the help with this.

frew

Edited by frew

Share this post


Link to post
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
Sign in to follow this  
Followers 0