Sign in to follow this  
Followers 0
Valuater

Having a problem with "Random()"

18 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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]

Share this post


Link to post
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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

works fine for me with 3.2.10

How odd!

Share this post


Link to post
Share on other sites

I see.... 3.2.12.0

For $x = 5 To 1 Step -1

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

ConsoleWrite( "x=" & $x & " Num=" & $Number & @CRLF)

Next

Example output

x=5 Num=2

x=4 Num=3

x=3 Num=3

x=2 Num=2

x=1 Num=0

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

this looks strange too

.99 min but an an integer result will be returned...

it should not be "0" here either..AFAIK

For $x = 5 To 1 Step -1

    $Number = Random(.99, $x, 1)
    ConsoleWrite( "x=" & $x & "   Num=" &  $Number & @CRLF)
    
Next

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

This has been reported and rejected (no bug): http://svn.autoitscript.com/trac/ticket/296

Thanks Saunders....

But what about this

For $x = 5 To 1 Step -1

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

ConsoleWrite( "x=" & $x & " Num=" & $Number & @CRLF)

Next

x=5 Num=3

x=4 Num=3

x=3 Num=3

x=2 Num=0

x=1 Num=1

I dont think there should be a 0 in there???

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

x=5 Num=5

x=4 Num=1

x=3 Num=0

x=2 Num=1

x=1 Num=1

???


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

Share this post


Link to post
Share on other sites

x=5 Num=5

x=4 Num=1

x=3 Num=0

x=2 Num=1

x=1 Num=1

???

yea... thats kinda funny

Random(.99, $x, 1)

will return a zero

:) Dunno!!...???

8)


NEWHeader1.png

Share this post


Link to post
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

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