Sign in to follow this  
Followers 0
Laurens

Random function

7 posts in this topic

Hi Guys!

I was just playing around with this awesome application but I cant seem to figure out the random function. I need to create a random number between 30 000 000 and 60 000 000 and write it back to a variable, the right approach would be :

Random, $var1, 30000000, 60000000

But I cant get this to work. Any help would be appriciated.

Thanks in advance.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi Guys!

I was just playing around with this awesome application but I cant seem to figure out the random function. I need to create a random number between 30 000 000 and 60 000 000 and write it back to a variable, the right approach would be :

Random, $var1, 30000000, 60000000

But I cant get this to work. Any help would be appriciated.

Thanks in advance.

something like

$var1 = Random(30000000, 60000000)

Also look at the help file for the functions that you want to use and it will give you some type of example.

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

I believe this would be correct if you were using AutoHotKeys, here is the syntax for this:

Random ( [Min [, Max [, Flag]]] )oÝ÷ Øw«{ljw±jjey«­¢+ÙI¹½´ ÌÀÀÀÀ°ØÀÀÀÀ¤oÝ÷ Øw«z+-ç±jjeyúèØ^éi~)^jëh×6;Flip of coin
If Random() < 0.5 Then  ; Returns a value between 0 and 1.
    $msg = "Heads. 50% Win"
Else
    $msg = "Tails. 50% Loss"
Endif
MsgBox(0,"Coin toss", $msg )


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

$StockPrice = 98
;In the middle of a stock market simulation game
$StockPriceChange = Random(-10, 10, 1)  ; generate an integer between -10 and 10
$StockPrice = $StockPrice + $StockPriceChange
If $StockPriceChange < 0 Then
    MsgBox(4096, "Stock Change", "Your stock dropped to $" & $StockPrice)
ElseIf $StockPriceChange > 0 Then
    MsgBox(4096, "Stock Change", "Your stock rose to $" & $StockPrice)
Else
    MsgBox(4096, "Stock Change", "Your stock stayed at $" & $StockPrice)
Endif


;Random letter
If Random() < 0.5 Then
    ;Capitals
    $Letter = Chr(Random(Asc("A"), Asc("Z"), 1))
Else
    ;Lower case
    $Letter = Chr(Random(Asc("a"), Asc("z"), 1))
Endif

[center]My BlogOldSock Programs (AutoIT Apps)A Message to Hackers! (NOT SKIDDIES!)OldSock Programs is my little "company."[/center]

Share this post


Link to post
Share on other sites

to make sure the result is an integer (if that is important to you)

$Var=Random(30000000,60000000,1)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hi Guys!

I was just playing around with this awesome application but I cant seem to figure out the random function. I need to create a random number between 30 000 000 and 60 000 000 and write it back to a variable, the right approach would be :

Random, $var1, 30000000, 60000000

But I cant get this to work. Any help would be appriciated.

Thanks in advance.

Umm that's AutoHotkey code. Make sure you're actually using the right scripting language's forum in the first place. :whistle:

Edited by xcal

Share this post


Link to post
Share on other sites

Umm that's AutoHotkey code. Make sure you're actually using the right scripting language's forum in the first place. :whistle:

Are you sure it's not AutoIt v2?

[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

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