1

I was trying to generate a random number in CAPL program (similar to C language) using timers. Say I have a timer X and I start it

/****Timer start****/
on start
{ 
  settimer (x,20000);   // setting the timer for 20 secs
}

Now I need a random number only between 300ms to 20 secs with a resolution of 500ms. CAPL has a inbuilt function called random() to do this.

I did like

int random(int x);

Now how can I make sure that I get a random value only with resolution of 500ms?

Any suggestions?

2 Answers 2

1

How about

y = random(40);
TestWaitForTimeout(300+y*500);

y gets a random value between 0 and 39, corresponding to 0-19.5 seconds with 500 ms resolution. Then you add 300ms to the total timeout. The resulting timeout will be between 300ms and 20s with a resolution of 500ms.

Sign up to request clarification or add additional context in comments.

Comments

0

I was able to generate random numbers by writing a test function as below. The random function generates a random number between 0 to n-1. As far as resolution is concerned the library function random() doesn't allow to vary the resolution.

testfunction Random_No ()

{

dword y;

y = random(20000);


TestWaitForTimeout(y);

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.