Real variable randomization

I am randomizing class which has bit variables and a real variable “freq”. freq should work on only 2,3,4 values.
How can i randomize class having real variable using systemverilog?

In reply to K_123:

You can randomize an integer variable and then in post_randomiztion assign that value x 1.0 to the real variable. sen Cohen
http://www.systemverilog.us/ ben@systemverilog.us
For training, consulting, services: contact Home - My cvcblr

** SVA Handbook 4th Edition, 2016 ISBN 978-1518681448

  1. SVA Package: Dynamic and range delays and repeats SVA: Package for dynamic and range delays and repeats | Verification Academy
  2. Free books: Component Design by Example FREE BOOK: Component Design by Example … A Step-by-Step Process Using VHDL with UART as Vehicle | Verification Academy
    Real Chip Design and Verification Using Verilog and VHDL($3) Amazon.com
  3. Papers:

In reply to K_123:

According to the SystemVerilog LRM, random variables can only have integral types. You can use post_randomize to convert an integral value to a real.

class A;
  rand int freq_int;
  real     freq_real;
  constraint f { freq_int inside {21, 32, 43};}
  function void post_randomize();
     freq_real = freq_int/10.0;
  endfunction
endclass

freq_real will be 2.1, 3.2, or 4.3.

In reply to dave_59:
hi Dave ,
can we modify the post_randomize function by using the casting ?

 
function void post_randomize();
 freq_real = real'((freq_int)/32'd10 );
  endfunction

In reply to Bandaru sateesh:
The problem with doing it that way is you’re performing integer division which truncates the fractional part, then converts it to a real.