# Generate clock jitter in a testbench

How would you generate clock jitter in a testbench?

I have seen these two ways, but I am not sure if they are the best ways:

always #(period/2+$random(-jitter/2,jitter/2) ) clk = ~clk; always #(period/2+$dist_uniform(seed,-jitter,jitter)) clk = ~clk;

• It really depends on what your testbench is trying to test by introducing jitter. Are there multiple clocks that need to keep in phase, then you need to make sure the overall frequency remains the same and just move the edges. – dave_59 Jun 27 '19 at 1:41
• Define "best". Also, define what it is you hope to learn by simulating jitter. I've never seen the point -- If you think you have potential setup/hold violations, static timing analysis is a much more useful tool. If you're trying to determine the jitter transfer characteristics of a system, there are more direct ways to analyze that, too. Otherwise, you have to run a very long simulation in order to gather a statistically significant amount of data. – Dave Tweed Jun 27 '19 at 12:22