ive got this code in my program

timer4.interval:=4000;

now i want to make the 4000 a random number between

12000 and 32000 how do i do it ?

timer4.interval:=4000;

now i want to make the 4000 a random number between

12000 and 32000 how do i do it ?

test : boolean;

num : integer;

begin

test := false;

Randomize;

while not test do

begin

num := round((random) * 100000);

if (num >= 12000) and (num <= 32000) then test := true;

end;

timer4.interval:= num;

end;

begin

Randomize;

Timer4.Interval := 12000 + Random(32000);

end;

I hope this helps,

Stu.

pass parameters to the updatetimeinterval event as below..

procedure tform1.updatetimeinterval(

begin

randomize;

timer4.interval := offset + ((random(range div granularity)+1)* granularity);

end;

ex of use

updatetimeinterval(12000,2

or have application-wide or unit-wide variables declared as part of a initialization sequence at startup

offset#,

range#,

granularity# : integer;

you may have multiple timers with different rules so just stick in the appropriate timer's parameters as offset0, range0, and granularity0 for timer0, and so on...

procedure tform1.updatetime#interval

begin

randomize;

timer#.interval := offset# + ((random(range# div granularity#)+1)* granularity#);

end;

replacing the # with timer #'s

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

you have a starting point at 12000 so that's a constant

the remainder is 20000 of which you need a randomized chunk

let's assume the startvalue is 12000

also let's assume you want granularity of 500 ticks

then endvalue would be 12000 + ((random(40)+1)*500)

because random(x) provides values from 0 -> (x-1)

we want 1 -> x so we add 1 to the random before we multiply anything

let's assume you want granularity of 100 ticks

then endvalue would be 12000 + ((random(200)+1)*100)

let's assume you want granularity of 250 ticks

then endvalue would be 12000 + ((random(80)+1)*250)

let's assume you want granularity of 1000 ticks

then endvalue would be 12000 + ((random(20)+1)*1000)

does that help at all