Search code examples
verilogverificationsystem-verilog

Can I use $urandom_range with time variables?


I wanted to know if I can simply write:

 time time_var;
 time_var = $urandom_range (10ms, 7ms);

I've tried using it directly, and there are no errors/warnings issued. However, the returned value is not between 7-10ms. I guess it's legal to use $urandom_range with time literals, since I didn't receive any errors. But, why can't I get a value in the proper range?


Solution

  • The IEEE Std (1800-2009) declares the arguments to $urandom_range to be of type int unsigned which is not the same as time. I don't think you can rely on the system function to behave predictably even if you are not getting errors or warnings from your simulator.

    It is a compile error in VCS and a warning with Incisive.

    Can you use something like this?

    int unsigned del = $urandom_range(10, 7);
    #(1ms * del);