SRL Archive - SRL Archives

rWait (Upgraded DivWait)


XxKanexX

2006-03-20 07:20:56

procedure rWait(ms: integer); - By XxKanexX

If you are going to use this please read My DivWait thread so you can get an understanding of what this is based about.


[FONT="Courier New"]Procedure rWait(ms: Integer);
var
i, diva, a: Integer;
begin

a:= Getsystemtime;
if(ms <= 0)then
ms:= 5;

Diva:= ms div(ms div(Random(ms div(ms div(ms-(ms-Random(ms+1 div 2))+1)+1)+1)+1)+1);

if(Diva <= 0)then
Diva:= ms/((ms/4)+1);

for I:= 1 to Diva do
begin
Wait(ms/diva + random(diva));
if(Random(100)+1 = Random(100)+1)then
Wait(Diva + Random(Diva div 2));
if(trunc(Getsystemtime-a) > ms * ((Random(7)+2 + Random(3)+1)/(Random(2)+1)))then
Break;
end;

if(Trunc(Getsystemtime-a) = ms)or (Trunc(Getsystemtime-a) < ms + (ms/4+(Random(3)+1)))then
wait(Random(ms));

end;[/FONT]

In Divwait you had to choose it's divisision and random wait time. Well, in this all you need to specify is the time. The rest is COMPLETELY random.

It divides the total wait time by a random number calculated by how big or small the wait time is (Just so it dosn't wait to long or not long enough).

If it waits more than a certain random time times by the total time then it will break.
If it waits the same amount as the time, it will wait a random time just so it's not the same.

At first i got division errors, but now everything is working. I ran it around 2000 times and not 1 division error. Dosn't mean it's not possible though.

I wouldn't suggest using this if you want to wait only the time you want to. This can increase it by a high amount.

It has a 1 out of 100 chance of waiting longer every time it waits a section.

Heres an example script:

[FONT="Courier New"]var
st, i: integer;
begin
for i:= 1 to 7 do
begin
st:= getsystemtime;
rwait(1000);
writeln(floattostr(getsystemtime-st));
end;
end.[/FONT]

And the results (In Milliseconds):

3915
2093
1743
1682
2594
3976
1543

I won't add this to SRL until i get everyones opinion. Should it be added?


Sorry if that's alot of explaining. I normally want to explain it enough for everyone to understand. :)

I highlight keywords in bold to annoy Fakawi ^^;; kekeke

Lorax

2006-03-20 08:17:02

Hello Kane sorry for being so slow on this, but I think the one I just made is better.

program new;

var i2: Integer;

procedure rWait(ms, min: Integer);
var
i, tRan, tVal: Integer;
begin
if Length(IntToStr(ms)) > 1 then
tVal:= Round(Length(IntToStr(ms)) div 2.0)
else
tVal:= 1;
repeat
for i := 1 to tVal do
tRan := tRan + Random(ms div tVal) div 2;
tVal := Random(4);
if(tVal = 3)or(tVal = 2)then
tRan := tRan * -1;
until(ms + tRan >= min);
WriteLn(IntToStr(ms) + 'ms = ' + IntToStr(ms + tRan));
Wait(ms + tRan);
end;

begin
ClearDebug;
for i2 := 1 to 2 do
rWait(2 * i2, 2);
for i2 := 1 to 2 do
rWait(20 * i2, 15);
for i2 := 1 to 2 do
rWait(50 * i2, 40);
for i2 := 1 to 2 do
rWait(100 * i2, 80);
for i2 := 1 to 2 do
rWait(1000 * i2, 800);
for i2 := 1 to 2 do
rWait(10000 * i2, 7000);
end.

here you can test it and the procedure in it self:

procedure rWait(ms, min: Integer);
var
i, tRan, tVal: Integer;
begin
if Length(IntToStr(ms)) > 1 then
tVal:= Round(Length(IntToStr(ms)) div 2.0)
else
tVal:= 1;
repeat
for i := 1 to tVal do
tRan := tRan + Random(ms div tVal) div 2;
tVal := Random(4);
if(tVal = 3)or(tVal = 2)then
tRan := tRan * -1;
until(ms + tRan >= min);
Wait(ms + tRan);
end;

try it out. it gives some nice results, min and max can be added / removed if you wish to.

Krazy_Meerkat

2006-03-20 16:13:06

Wow good work guys. I like kanes one a little more because it just spreads out a little more and not much input was required.
I see that you have both know that it's important not to wait less than the specified wait time. I used code which was a little simpler, but still did the same job.
procedure ChanceWait(NormalWait: integer);
begin
if (random(100) < 5) then
wait((NormalWait * 2) + random(round(NormalWait div 2)));
else
wait(NormalWait);
end;
I wasn't sure if NormalWait should have some random time added to it, the extended wait does :/

Lorax

2006-03-21 12:09:06

From: Krazy_Meerkat
Wow good work guys. I like kanes one a little more because it just spreads out a little more and not much input was required.
I see that you have both know that it's important not to wait less than the specified wait time. I used code which was a little simpler, but still did the same job.
procedure ChanceWait(NormalWait: integer);
begin
if (random(100) < 5) then
wait((NormalWait * 2) + random(round(NormalWait div 2)));
else
wait(NormalWait);
end;
I wasn't sure if NormalWait should have some random time added to it, the extended wait does :/

That's a pretty bad wait procedure, mine and Kane's are more random, and off course mine is within the acceptable limits of randomness

Brown

2006-03-21 15:57:23

3915
2093
1743
1682
2594
3976
1543

Nice on the randomness. Im going to hafta use this in future scripts.

Awesome job :).

Krazy_Meerkat

2006-03-21 16:57:59

You're right lorax, it was just an example :)
I've changed my mind, I think that lorax's one is a lot better (but you just need to get rid of that extra parameter).
I've taken the liberty to do it myself. You don't mind if I use this do you lorax?
program new;

var i2: Integer;

procedure rWait(ms: Integer);
var
i, tRan, tVal, min: Integer;
begin
min:= ms
if Length(IntToStr(ms)) > 1 then
tVal:= Round(Length(IntToStr(ms)) div 2.0)
else
tVal:= 1;
repeat
for i := 1 to tVal do
tRan := tRan + Random(ms div tVal) div 2;
tVal := Random(4);
if(tVal = 3)or(tVal = 2)then
tRan := tRan * -1;
until(ms + tRan >= min);
WriteLn(IntToStr(ms) + 'ms = ' + IntToStr(ms + tRan));
Wait(ms + tRan);
end;

begin
ClearDebug;
rWait(500);
end.

XxKanexX

2006-03-22 06:19:00

From: Krazy_Meerkat
You're right lorax, it was just an example :)
I've changed my mind, I think that lorax's one is a lot better (but you just need to get rid of that extra parameter).
I've taken the liberty to do it myself. You don't mind if I use this do you lorax?
program new;

var i2: Integer;

procedure rWait(ms: Integer);
var
i, tRan, tVal, min: Integer;
begin
min:= ms
if Length(IntToStr(ms)) > 1 then
tVal:= Round(Length(IntToStr(ms)) div 2.0)
else
tVal:= 1;
repeat
for i := 1 to tVal do
tRan := tRan + Random(ms div tVal) div 2;
tVal := Random(4);
if(tVal = 3)or(tVal = 2)then
tRan := tRan * -1;
until(ms + tRan >= min);
WriteLn(IntToStr(ms) + 'ms = ' + IntToStr(ms + tRan));
Wait(ms + tRan);
end;

begin
ClearDebug;
rWait(500);
end.

Harsh ;(:(

Krazy_Meerkat

2006-03-22 15:29:02

No kaney you got it all wrong, I think it is a lot better than what I did before. I still <3 rWait

Lorax

2006-03-23 07:29:41

From: Krazy_Meerkat
No kaney you got it all wrong, I think it is a lot better than what I did before. I still <3 rWait
I like the way you modified it, hehe. I added a possibility to wait the random less on the first script that can be removed though :
First procedure:
procedure rWait(ms, min: Integer);
var
i, tRan, tVal: Integer;
begin
if Length(IntToStr(ms)) > 1 then
tVal:= Round(Length(IntToStr(ms)) div 2.0)
else
tVal:= 1;
repeat
for i := 1 to tVal do
tRan := tRan + Random(ms div tVal) div 2;
tVal := Random(4);
if(tVal = 3)or(tVal = 2)then
tRan := tRan * -1;
until(ms + tRan >= min);
Wait(ms + tRan);
end;


procedure with removed ability to wait less than ms:
procedure rWait(ms: Integer);
var
i, tRan: Integer;
begin
if Length(IntToStr(ms)) > 1 then
tVal:= Round(Length(IntToStr(ms)) div 2.0)
else
tVal:= 1;
for i := 1 to tVal do
tRan := tRan + Random(ms div tVal) div 2;
Wait(ms + tRan);
end;