MathRand between 3000 and 5000

 

All,


I am looking to get a random number between 3000 and 5000 that will be passed into the Sleep().


here is what I am came up with, while it works, I wanted to ask if there was a better way to get the same result.


the issue I am coming across is when I send multiple alerts to telegram and not all of them arrive, I understand that telegram will prevent 20 messages per second or per minute. therefor I need the EA to sleep for a random number of seconds between 3-5 before sending the alert. After trying just the sleep and getting blocked, I determined I need for the alert to be sent out at random within 3-5 will allow for all alerts to be delivered. I suppose the time it takes for the EA to get a number between 3000-5000 out 32767 also take into account when the alert will be sent. I suppose what I have below will work, but I did want to get a different perspective.


   MathSrand(GetTickCount());

   int RandSec = MathRand();
   
   while(RandSec>3000 && RandSec<5000 && !IsStopped())
   {
   RandSec = MathRand();
   }
 
Ähm. Yes. There is.

Your original code did not do what you expected.

This version is inclusive 3000 and 5000.

Take a look:

while((RandSec<3000 || RandSec>5000) && !IsStopped())
   {
   RandSec = MathRand();
   }
 
Dominik Christian Egert #:
Ähm. Yes. There is.

Your original code did not do what you expected.

Take a look:

Exactly what I looking for, a simple mistake on my part.

 
Dominik Christian Egert #:
Ähm. Yes. There is.

Your original code did not do what you expected.

This version is inclusive 3000 and 5000.

Take a look:

If I do || instead of && my terminal will freeze.

 
Dominik Christian Egert #:


thanks this helped. 

Reason: