Control over randomization without using constraint

I have a variable which is int and i need to randomize it and print only 0 & 3 using $randomrange() how it can be done??

In reply to araj380:


module print_0or3_only;
  int var_1;

  initial begin
    repeat(30) begin
      var_1 = 3 * $urandom_range(0,1);
      $display("\nvar_1 = %0d",var_1);
    end
  end
endmodule

In reply to Shashank Gurijala:

In reply to araj380:


module print_0or3_only;
int var_1;
initial begin
repeat(30) begin
var_1 = 3 * $urandom_range(0,1);
$display("\nvar_1 = %0d",var_1);
end
end
endmodule

what if the values increase…let say now i want to print 0,3,5,6,8,9 then how i can write it in efficient way

In reply to araj380:


module print_req_values;
  int var_1;
  int array[] = {0,3,19,37,52,85,99}; //if more values are needed, the respective elements can be added 
  
  initial begin
    $display("\nThe values that are needed : %0p",array);
    repeat(250) begin
      var_1 = $urandom_range(array.min()[0],array.max()[0]);
      while (!(var_1 inside {array}))  var_1 = $urandom_range(array.min()[0],array.max()[0]);
      $display("\nvar_1 = %0d",var_1);
    end
  end	
endmodule