Jump to content
Sign in to follow this  
Kanske

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

Recommended Posts

Kanske

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
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Kanske

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
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Kanske

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
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Kanske

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  

×