DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: AleaPause  (Read 11,192 times)

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
AleaPause
« on: January 07, 2014, 12:16 AM »

The idea is simple.

Delay the execution of a loop or Do While with an aleatory time in a range.
So I think i need an ini file to control the minimum time and the maximum time.
By example.
I have to do the next task in the range (1/2 hour to 1 hour)
In the ini file : 30, 60 minutes or any other accorded configuration.
The script don't liberate or allows the next step in my script until the time is passed.
I will insert the AleaPause script in my script to control aleatory times in a predefined range of time.
When the first task is done, enter AleaPause, then when finished the second task and so on while the loop ... do while .... enddo is acting.


Is this possible ?
:-*

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: AleaPause
« Reply #1 on: January 07, 2014, 12:55 AM »
Sleep.cmd

Hardcoded:
Code: (generic)
REM Generate random number between 30 and 60
set /a num=%RANDOM% * (%%60 - %%30 + 1) / 32768 + %%30

REM Multiply by 60 for minutes
set /a delay = %num% * 60

REM Wait (timeout is a Win 7+ command)
timeout %delay%


The non hardcoded version:
Code: (generic)
REM Generate random number between first and second argument
REM Second argument > first argument
set /a num=%RANDOM% * (%2 - %1 + 1) / 32768 + %1

REM Multiply by 60 for minutes
set /a delay = %num% * 60

REM Wait (timeout is a Win 7+ command)
timeout %delay%

Sleep.cmd 30 60
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903
« Last Edit: January 07, 2014, 02:22 AM by 4wd »

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: AleaPause
« Reply #2 on: January 07, 2014, 01:57 AM »
Sleep.cmd

Hardcoded:
Code: (generic)
REM Generate random number between 30 and 60
set /a num=%random% %%60 +30

REM Multiply by 60 for minutes
set /a delay = %num% * 60

REM Wait (timeout is a Win 7+ command)
timeout %delay%


The non hardcoded version:
Code: (generic)
REM Generate random number between first and second argument
REM Second argument > first argument
set /a num=%random% %%%2 +%1

REM Multiply by 60 for minutes
set /a delay = %num% * 60

REM Wait (timeout is a Win 7+ command)
timeout %delay%

Sleep.cmd 30 60


but where is the ini file ?
:-[

I can understand almost in the batch language. I'll try executing. It's the best.

Best Regards
:-*

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: AleaPause
« Reply #3 on: January 07, 2014, 02:07 AM »
One consideration.
I will run this script in a virtual machine under windows xp pro
And perhaps under windows 7 someday.
The hard code option offer the console with the counting. I would like something more interactive.
I have to edit the cmd file to vary the arguments.
:P

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: AleaPause
« Reply #4 on: January 07, 2014, 02:10 AM »
something fails.
Begin with 4860 seconds. More than 1 hour.
The target was between 1/2 hour and 1 hour.
:-[

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: AleaPause
« Reply #5 on: January 07, 2014, 02:23 AM »
Begin with 4860 seconds. More than 1 hour.
The target was between 1/2 hour and 1 hour.

Fixed.

For XP:
Code: (generic)
REM For XP
@echo off

REM Generate random number between first and second argument
REM Second argument > first argument
set /a num=%RANDOM% * (%2 - %1 + 1) / 32768 + %1
 
REM Multiply by 60 for minutes
set /a delay = %num% * 60
 
REM Ping an invalid IP once per second
for /l %%a in (1,1,%delay%) do (ping 1.1.1.1 -n 1 -w 1000 > nul)
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903
« Last Edit: January 07, 2014, 02:32 AM by 4wd »

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: AleaPause
« Reply #6 on: January 07, 2014, 02:29 AM »
The final script will be compiled.
So I can't vary easily sleep.cmd 30 60
:tellme:

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: AleaPause
« Reply #7 on: January 07, 2014, 02:31 AM »
Begin with 4860 seconds. More than 1 hour.
The target was between 1/2 hour and 1 hour.

Fixed.

Why the hard coded version don't remail the console window ?
I see nothing
:(

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: AleaPause
« Reply #8 on: January 07, 2014, 02:38 AM »
The final script will be compiled.

So just add the relevant script commands in your program to cause a delay in whatever script language you're using ... since you haven't told us.
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: AleaPause
« Reply #9 on: January 07, 2014, 02:39 AM »
xp version fails too.
Invalid IP why ?
:-*

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: AleaPause
« Reply #10 on: January 07, 2014, 02:40 AM »
The final script will be compiled.

So just add the relevant script commands in your program to cause a delay in whatever script language you're using ... since you haven't told us.

Will be dBASE
:P

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: AleaPause
« Reply #11 on: January 07, 2014, 07:58 AM »
xp version fails too.
Invalid IP why ?

Um, because it's supposed to?

Works OK on my XP machine and you'll never see the result of the ping unless you've modified the ping command (> nul) or your systems redirection is borked.

Code: (generic)
REM For XP
@echo off

REM Generate random number between first and second argument
REM Second argument > first argument
set /a num=%RANDOM% * (%2 - %1 + 1) / 32768 + %1
 
REM Multiply by 60 for minutes
set /a delay = %num% * 60
 
REM Ping an invalid IP once per second        <---------------------------------------------------------------
for /l %%a in (1,1,%delay%) do (ping 1.1.1.1 -n 1 -w 1000 > nul)
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: AleaPause
« Reply #12 on: January 07, 2014, 05:18 PM »
xp version fails too.
Invalid IP why ?

Um, because it's supposed to?

Works OK on my XP machine and you'll never see the result of the ping unless you've modified the ping command (> nul) or your systems redirection is borked.

Code: (generic)
REM For XP
@echo off

REM Generate random number between first and second argument
REM Second argument > first argument
set /a num=%RANDOM% * (%2 - %1 + 1) / 32768 + %1
 
REM Multiply by 60 for minutes
set /a delay = %num% * 60
 
REM Ping an invalid IP once per second        <---------------------------------------------------------------
for /l %%a in (1,1,%delay%) do (ping 1.1.1.1 -n 1 -w 1000 > nul)

Trying. I don't understand everything , but I will try
:P

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: AleaPause
« Reply #13 on: January 07, 2014, 05:23 PM »
xp version fails too.
Invalid IP why ?

Um, because it's supposed to?

Works OK on my XP machine and you'll never see the result of the ping unless you've modified the ping command (> nul) or your systems redirection is borked.

Code: (generic)
REM For XP
@echo off

REM Generate random number between first and second argument
REM Second argument > first argument
set /a num=%RANDOM% * (%2 - %1 + 1) / 32768 + %1
 
REM Multiply by 60 for minutes
set /a delay = %num% * 60
 
REM Ping an invalid IP once per second        <---------------------------------------------------------------
for /l %%a in (1,1,%delay%) do (ping 1.1.1.1 -n 1 -w 1000 > nul)

Trying. I don't understand everything , but I will try
:P

In seven fails to me.
In xp under virtual machine fails to me.
I don't know what i am doing bad.
First time open a console window. Now never in seven.

What can i do to depure this ?

Best Regards
:-*

Original address: https://www.donationcoder.com/forum/index.php?topic=36961.0