Jump to content

Having a problem with "Random()"


Recommended Posts

I would think this should return a "1"

$Number = Random(1,1,1)

MsgBox(0x0,"", $Number)

but...not!!!...???

I am looping though an array and it gets down to $x being a 1..

$Number = Random(1,$x,1)

then it errors by returning a "0"

8)

v3.2.12.0

win xp sp3

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

$Number = Random(1,1,1)
MsgBox(0x0,"", $Number)

This does return a 1... at least, it did for me. Are you sure the value of $x is 1 when you have the problem?

Edited by Airwolf123
Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
Link to comment
Share on other sites

What version of AutoIt are your two using...

I always get a 0 using Val's code using v3.2.12.0

Edit: or this code...

ConsoleWrite(@CR)
For $i = 1 To 10
    $Number = Random(1, 1, 1)
    ConsoleWrite($Number & @CR)
Next
ConsoleWrite(@CR)
Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

What version of AutoIt are your two using...

I always get a 0 using Val's code using v3.2.12.0

Edit: or this code...

ConsoleWrite(@CR)
For $i = 1 To 10
    $Number = Random(1, 1, 1)
    ConsoleWrite($Number & @CR)
Next
ConsoleWrite(@CR)oÝ÷ Ûú®¢×­+&mmæ¥Ûezj+z·©­ëÖ­÷¨~Ø^¦ºjëh×6For $x = 5 To 1 Step -1

    $Number = Random(1, $x, 1)
    MsgBox(0x0, $x, $Number, 2)

Next

thx

8)

NEWHeader1.png

Link to comment
Share on other sites

this might be a little more representative of the prob...

For $x = 5 To 1 Step -1

    $Number = Random(1, $x, 1)
    MsgBox(0x0, $x, $Number, 2)

Next

thx

8)

I know that is like the code that you are having problems with but you only get Random(1, $x, 1) to be Random(1, 1, 1) one time in that code.

I was going for a repetition of Random(1, 1, 1)

I get zero 10 out of 10 times with my little loop :-(

What version of AutoIt are you using Val?

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

...and a 1000 0s using v3.2.12.0

Nothing in the changelog for Random() that I saw.

Edit: Correction - the full changelog does show two "fixes" to Random:

http://www.autoitscript.com/autoit3/docs/a...t_changelog.txt

- Fixed: AutoIt crash in Random() when range exceeds 2^31.

- Fixed: Random(Min,Max,1). Previously this would never actually return Max,

so if Max was artificially incremented by one the script will now need to be changed.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

...and a 1000 0s using v3.2.12.0

Nothing in the changelog for Random() that I saw.

Edit: Correction - the full changelog does show two "fixes" to Random:

http://www.autoitscript.com/autoit3/docs/a...t_changelog.txt

- Fixed: AutoIt crash in Random() when range exceeds 2^31.

- Fixed: Random(Min,Max,1). Previously this would never actually return Max,

so if Max was artificially incremented by one the script will now need to be changed.

I remember seeing that before, it may have "created" another bug area...

thx

8)

NEWHeader1.png

Link to comment
Share on other sites

yea... thats kinda funny

Random(.99, $x, 1)

will return a zero

:) Dunno!!...???

8)

It sets @error = 1 also, indicating invalid parameters:
For $x = 5 To 1 Step -1
    ConsoleWrite(@LF & "Debug: $x = " & $x & @LF)
    For $y = 1 To 5
        $n = Random(1, $x, 1)
        ConsoleWrite("Debug: $n = " & $n & "  @error = " & @error & @LF)
    Next
Next

So it may be as intended and just needs a update to the help file description that Min cannot equal Max. This does the same:

For $x = 5 To 2 Step -1
    ConsoleWrite(@LF & "Debug: $x = " & $x & @LF)
    For $y = 1 To 5
        $n = Random(2, $x, 1)
        ConsoleWrite("Debug: $n = " & $n & "  @error = " & @error & @LF)
    Next
Next

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...