# Random function

## Recommended Posts

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.

##### Share on other sites

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.

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."

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

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 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.
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 on other sites

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

\$Var=Random(30000000,60000000,1)

##### Share on other sites

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.

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

Edited by xcal

##### 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.

Are you sure it's not AutoIt v2?

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.

##### Share on other sites

Oh, I suppose that's possible. That's before my time.

Edited by xcal

## Create an account

Register a new account

×

• Wiki

• Back

• Git