Randomization of multiple of N

In reply to jh_veryveri:

(In my honest opinion and without wanting to sound rude) : It’s a good idea to show some code which demonstrates that you have tried solving this. If you are running into issues, you can then request help. Asking for complete solutions is not going to help you.

One of the possible solutions to your question is the below code. You can modify it to suit your use case.


class A;
  int n;
  
  rand logic [7:0] my_var;
  constraint my_var_c {my_var % n == 0;};
  
  function disp();
    $display("my_var is %0d", my_var);
  endfunction
endclass


module top;
  A a1 = new();
  
  initial begin
    for(int i = 1; i < 5; i++) begin
      a1.n = i;
      $display("Multiplier is %0d", i);
      repeat(10) begin
        a1.randomize();
        a1.disp();
      end
      
    end
    
    
  end
endmodule