Jump to content

Random variable


MattX
 Share

Recommended Posts

I have in a script a few hundred variables. All declared as:

Dim $ex1="variable 1"
Dim $ex2="variable 2"
Dim $ex3="variable 3"
Dim $ex4="variable 4"

Etc

I am wondering how I could use the Random function to choose one ? Can someone give me a pointer ?

Link to comment
Share on other sites

I have in a script a few hundred variables. All declared as:

Dim $ex1="variable 1"
Dim $ex2="variable 2"
Dim $ex3="variable 3"
Dim $ex4="variable 4"

Etc

I am wondering how I could use the Random function to choose one ? Can someone give me a pointer ?

Hi, you will need to build an algoritm of your own or use an existing one with Array to hold all the variables entries. you can put all the variables inside an array of 256 entries and then call that array using $i which:

$i=Random (1,256,0)
$m=$E[$i]
msgbox (0,"this is $m:",$m)

every time you will start the script $m will holds different values.

Link to comment
Share on other sites

Hi, you will need to build an algoritm of your own or use an existing one with Array to hold all the variables entries. you can put all the variables inside an array of 256 entries and then call that array using $i which:

$i=Random (1,256,0)
$m=$E[$i]
msgbox (0,"this is $m:",$m)

every time you will start the script $m will holds different values.

And there was me thinking it would be something like :

Dim $ex1="variable 1"
Dim $ex2="variable 2"
Dim $ex3="variable 3"
Dim $ex4="variable 4"

$excuse = Random ( $ex1, $ex4 )
MsgBox(0, "box", $excuse)

Thing is I have around 500 variables......

I'm not too sure on the Array method if I am restricted to 256 entries

Link to comment
Share on other sites

And there was me thinking it would be something like :

Dim $ex1="variable 1"
Dim $ex2="variable 2"
Dim $ex3="variable 3"
Dim $ex4="variable 4"

$excuse = Random ( $ex1, $ex4 )
MsgBox(0, "box", $excuse)

Thing is I have around 500 variables......

I'm not too sure on the Array method if I am restricted to 256 entries

here is your solution:

dim $E[5000]; an Array that holds 5000 var.... (amaizing haaa)....

because you didn't use variables in the first place I guess those 500 variables are filling all of your config, so you will have to have 500 lines like these:

$E[1]=$ex1

$E[2]=$ex2

......

$E[500]=$ex500.

which is petty but never mind I would use an Array to hold those, but it will solve you problem.

Link to comment
Share on other sites

Never can get the hang of arrays - this just does nothing !!

Dim $e="variable1"
Dim $e="variable2"
Dim $e="variable3"
Dim $e="variable4"
Dim $e="variable5"
Dim $e="variable6"
Dim $e="variable7"
Dim $e="variable8"
Dim $e="variable9"
Dim $e="variable10"

$i=Random (1,10,0)
$m=$e[$i]
msgbox (0,"this is $m:",$m)
Link to comment
Share on other sites

Never can get the hang of arrays - this just does nothing !!

Dim $e="variable1"
Dim $e="variable2"
Dim $e="variable3"
Dim $e="variable4"
Dim $e="variable5"
Dim $e="variable6"
Dim $e="variable7"
Dim $e="variable8"
Dim $e="variable9"
Dim $e="variable10"

$i=Random (1,10,0)
$m=$e[$i]
msgbox (0,"this is $m:",$m)
hi, here is what you tried to do to your code: (but it is not working because you havn't declared $e[$x] as Array):

$m=$e1

$m=$e5

$m=$e7

I guess you had alot of errors while checking it! because it will never work that way. you will have to insert your $eX to an Array.

Link to comment
Share on other sites

You don´t understand an array MattX

$e is ONE variable.

if you:

$e = 1

$e = 2

$e will ONLY be 2 and not 1 anymore.

To put serveral things in "one" variable you have to create an array.

A Array would be

$e[sizeOFARRAY]

at your script:

Dim $e[10]

$e[0] = "variable1"

$e[1] = "variable2" aso.

Look at my example:

CODE
Dim $test[5000]

for $i = 1 to 4999

$test[$i] = "Hello i am " & $i

Next

$test[0] = UBound($test)

$r = Random(1,$test[0])

$m=$test[$r]

msgbox (0,"this is $m:",$m & " The random was: " & $r)

Link to comment
Share on other sites

  • Developers

try:

Dim $e[11]
$e[1] = "variable1"
$e[2] =  "variable2"
$e[3] =  "variable3"
$e[4] =  "variable4"
$e[5] =  "variable5"
$e[6] =  "variable6"
$e[7] =  "variable7"
$e[8] =  "variable8"
$e[9] =  "variable9"
$e[10] =  "variable10"
$i = Random(1, 10, 0)
$m = $e[$i]
MsgBox(0, "this is $m:", $m)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You don´t understand an array MattX

$e is ONE variable.

if you:

$e = 1

$e = 2

$e will ONLY be 2 and not 1 anymore.

Yeah, sorry - that was me thinking I was making the array then....[ yup I am daft ]

With everyone's explanation and code I have this working now - thanks all !! [ and thanks for being so quick too !! ]

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...