Sign in to follow this  
Followers 0
Kanske

Why doesn't this very simple random script work properly?

7 posts in this topic

I have a loop, and within it I have the following script to output a random number between 9000 and 12500:

Send(Random(9000, 12500, 1))
      Send("{ENTER}")

Everything works fine, except it doesn't recognize the minimum number. As such, it prints out any number between 1 and 12500. It created the following sample output:

1268

1367

1211

9885

11177

1326

169

11912

12239

157

947

What did I do wrong and what should I do instead?

Share this post


Link to post
Share on other sites



If I test your code it works as expected:

For $i = 1 To 10
     ConsoleWrite(Random(9000, 12500, 1) & @LF)
Next
What version of AutoIt do you use?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

If I test your code it works as expected:

For $i = 1 To 10
     ConsoleWrite(Random(9000, 12500, 1) & @LF)
Next
What version of AutoIt do you use?

SciTE-Lite

Version 2.28

Jan 29 2012 21:33:22

Share this post


Link to post
Share on other sites

I didn't ask for the SciTE version but for the AutoIt version.

Please run this code:

Consolewrite(@AutoItVersion & @CRLF)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I didn't ask for the SciTE version but for the AutoIt version.

Please run this code:

Consolewrite(@AutoItVersion & @CRLF)

I apologize, I thought they were interlinked and thus the version would show up where it usually does (about).

The version output was 3.3.8.1

Share this post


Link to post
Share on other sites

Could you run the script I posted in So we can see if the problem is related to the Random function or to the program you send the output to.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Could you run the script I posted in So we can see if the problem is related to the Random function or to the program you send the output to.

I've tested yours and it works. However, if I replace Consolewrite with Send in your script, it stops working correctly. The active program it was sending to was both Notepad++ and the SciTE4AutoIt3 script window.

Looking through it again, I think I understand what was causing it now. As I had the button 0 binded to start the script, the random function stripped out all zeros. Changing the start button did resolve the issue. Wasn't entirely obvious to me as it is the first time I use the program, but with your help I could pin point it down. Thank you!

Edited by Kanske

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