Sign in to follow this  
Followers 0
mhosbo

Random Number help please

12 posts in this topic

Ok, before anyone tells me to read the help file or do a search, know that 1. I'm a beginner and 2. I searched for my answers before registering.

Here's my issue that I just can't figure out on my own. I spent 2 hours searching, reading and failing.

I need to do an unseeded random number between 950 and 1250, about 300 times.

Let me know if more information is required.

Share this post


Link to post
Share on other sites



mhosbo

Welcome to the AutoIt forum. :graduated:

I spent 2 hours searching, reading and failing

In that case I think you need some "searching, reading" classes. :D

Quoted from the Help file:

#-----------------------------

Random - Generates a pseudo-random float-type number.

Random ( [Min [, Max [, Flag]]] )

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.

Flag [optional] - If this is set to 1 then an integer result will be returned. Default is a floating point number.

#-----------------------------

So you would need:

Random(950, 1250, 1)

Now for doing this 300 times you need a loop. Again from the Help file under <Language Reference - Loop Statements> we find:

#-----------------------------

A loop is how you refer to a section of script that you repeat a number of times. You might want to loop a given number of times or you might wish to repeat a section of script as long as a certain condition is true or false.

The following loop statements are available in AutoIt:

For...Next

While...WEnd

Do...Until

For...In...Next

While (no pun intended) all the statements perform similar functions, they are slightly different and one will usually be more appropriate than another for a given situation

#-----------------------------

You would be best served by a For...Next loop - so let us look at that in the Help file:

#-----------------------------

For...To...Step...Next - Loop based on an expression.

For <variable> = <start> To <stop> [step <stepval>]

statements

...

Next

Parameters

variable - The variable used for the count.

start - The initial numeric value of the variable.

stop - The final numeric value of the variable.

stepval - [optional] The numeric value (possibly fractional) that the count is increased by each loop. Default is 1

#-----------------------------

So you would need:

For $i = 1 To 300
    ; Your random number generating code
Next

Now we need to think how to store the random numbers you generate - but you need to explain what you want to do with them first. :D

All clear so far? :(

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

At least I don't need failing classes, I've got that down.

Here's what I'm doing.

A number of MouseClicks, then send random number between 950 and 1250.

Same thing, over and over, with some other stuff in the middle that I've already figured out how to do.

I'm not doing this exactly 300 times. That number is unknown to me right now.

Share this post


Link to post
Share on other sites

mhosbo,

A number of MouseClicks, then send random number between 950 and 1250.

Same thing, over and over, with some other stuff in the middle that I've already figured out how to do

Now what does that make me think you are automating? :graduated:

How are you determining the number of passes through the loop? How do you know when it is time to stop? :(

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

#5 ·  Posted (edited)

It is automation that I'm going to use on a program at work. Is that illegal?

It will stop when I press esc. I'll be able to delete the records I don't need(on the work app) that are created through the macro.

Edited by mhosbo

Share this post


Link to post
Share on other sites

mhosbo,

Is that illegal?

My apologies - sounded a lot like a game! :graduated:

If you do not know how many passes you need, then I would suggest a While...WEnd loop which you break out of with the escape key:

#include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1 ; Start an infinite loop

    ; Random number code

    ; Other stuff

    If _IsPressed("1B", $dll) Then ExitLoop ; Exit loop if ESC pressed

WEnd

DllClose($dll)
Exit

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

I guess I'm just not cut out for this kinda stuff.

I'll just keep studying and hopefully it will click in my brain one day.

Thanks for trying to help.

Share this post


Link to post
Share on other sites

mhosbo,

Why give up so easily? You get help here as you have just seen. What about the code I posted do you not understand? :graduated:

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

I guess I was hoping to assign a random number to a variable.

That way, whenever I needed to send that random number, I could just do "Send ($n)"

Mouseclick ( )

Send ($n) ;random number between 950 and 1250

;code that opens a blank page

Mouseclick ( )

Send {$n)

Rinse and repeat.

Like I said before, I am extremely new to coding/programming. Just trying to make it easier on me and my co-workers.

Share this post


Link to post
Share on other sites

I guess I was hoping to assign a random number to a variable.

That way, whenever I needed to send that random number, I could just do "Send ($n)"

Mouseclick ( )

Send ($n) ;random number between 950 and 1250

;code that opens a blank page

Mouseclick ( )

Send {$n)

Rinse and repeat.

Like I said before, I am extremely new to coding/programming. Just trying to make it easier on me and my co-workers.

Whats so hard then?

Global $n = Random(950, 1250, 1)
Send($n)

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

Whats so hard then?

Global $n = Random(950, 1250, 1)
Send($n)

Using that returned the same number. Here's what I have.

Global $n = random(950, 1250, 1)

send ($n)

send ("{ENTER}")

send ($n)

send ("{ENTER}")

send ($n)

send ("{ENTER}")

Share this post


Link to post
Share on other sites

Of course it's the same number, you never change it!

$n = random(950, 1250, 1)
send ($n)
send ("{ENTER}")
$n = random(950, 1250, 1)
send ($n)

But this is a unnecessary way of doing it if you only use the numbers once. just do:

send (random(950, 1250, 1))
send ("{ENTER}")
send (random(950, 1250, 1))
send ("{ENTER}")

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