Jump to content

Autoit Random number help?


TheFixer
 Share

Recommended Posts

So I need some help...

basically all I want to do is have Autoit generate a random number between 1 and 3

and then have an if statement that reads the random number... and lets say if it = 3 it will say the number 3 in a msgbox

(like this)

sleep(500)

Random(1,3)

If Random = 2 Then
    MsgBox(0,"","2")
EndIf

If Random = 1 Then
    MsgBox(0,"","1")
EndIf

If Random = 3 Then
    MsgBox(0,"","3")
EndIf

can anyone help me? (thanks in advance!)

Link to comment
Share on other sites

  • Moderators

TheFixer,

Get the random number and then use a Switch structure to distinguish between the 3 returns - look in the Help file to see the syntax.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

TheFixer,

Get the random number and then use a Switch structure to distinguish between the 3 returns - look in the Help file to see the syntax.

M23

I hope you don't mind but could you give me a little example? (I work best with examples & having things explained to me like I'm stupid pretty much lol)

Link to comment
Share on other sites

  • Moderators

TheFixer,

What do you not understand about the example for Switch in the Help file? Does that not explain how to use the function well enough?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

$iRandomNumber = Random(1, 3, 1)

Switch $iRandomNumber
    Case 1
        ; Code
    
    Case 2
        ; Code
    
    Case 3
        ; Code
EndSwitch

 

Edited by TheDcoder
speeling

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

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

×
×
  • Create New...