What is the best way to get a randomized real value?

Hello !

a. For example I just tried declaring a variable as given below and applied the constraints. Things were working fine, but I see people posting we can’t use rand real and constraints.

b. Is the below coding style accepted to generate random real numbers ? Or is it just the tool supported format. [Tried running in cadence simulator]


 class volt;
   rand real voltage;
 
   constraint voltage_c {
     voltage inside {[1.5:2.5]}
   }
 endclass: volt

Share in your comments/thought process !

Thanks