Thanks, but all generated vectors will be random, ryt? I need to ensure all the 25 bit one hot encoded vectors are inside my range. How is that possible?
In reply to Gokul S:
You were not clear on your requirements. If you need to generate 25 25-bit one-hot numbers and don’t care about repetition the constraint that Steve gave you works if you call randomize 25 times. If you do not want repetition, use the randc qualifier as shown below.
module top;
class A;
randc [24:0] vector;
constraint one hot { $countones(vector) == 1; }
endclass
A h;
initial begin
h = new;
repeat (25) begin
assert (h.randomize());
$displayb(h.vector);
end
end
endmodule
In reply to Gokul S:
You were not clear on your requirements. If you need to generate 25 25-bit one-hot numbers and don’t care about repetition the constraint that Steve gave you works if you call randomize 25 times. If you do not want repetition, use the randc qualifier as shown below.
module top;
class A;
randc [24:0] vector;
constraint one hot { $countones(vector) == 1; }
endclass
A h;
initial begin
h = new;
repeat (25) begin
assert (h.randomize());
$displayb(h.vector);
end
end
endmodule
I thought randc can take only a max of 16 bits for a possible 65536 values.
I ran the program and i am getting compile Error. Can you help?
module top;
class A;
randc bit [24:0] vector;
constraint one_hot { $countones(vector) == 1; }
endclass
A h;
initial begin
h = new;
repeat (25) begin
assert (h.randomize());
$displayb(h.vector);
end
end
endmodule
rror-[IVCB-NORANDC] Illegal use of randc variable
design.sv, 5
top, “this.vector”
The expression contains the variable vector of type randc and cannot be used
in solve-before, distribution, unique and function calls.
Change the type of the randc variable or remove it from the expression.
I tried to this using a dynamic array but, it is not working for me. IN EDA playground it is timing out. Not sure if there is any issue in my constraint. I should try this probably in my work place environment and, see as well.
This is getting timed out after a min or 2. Is this some stack mem limitation of EDA Tools that is using Synopsys VCS 2014.
module top;
class A;
rand bit [24:0] vector[];
constraint one_hot {
vector.size() == 25;
foreach(vector[i])
$countones(vector[i]) == 1;
}
constraint c_uniq {
unique {vector};
}
endclass
//A h;
module top ();
initial begin
A h = new;
//repeat (25) begin
assert (h.randomize());
$displayb(h.vector);
//end
end
endmodule
The following constraint will generate the one-hot vector however it will not generated walking one pattern ;
module top ;
class onehot ;
rand bit [24:0] vector ;
constraint c_vector {
(vector & (vector-1)) == 0;
}
endclass
initial begin
onehot o ;
o = new ;
repeat(10)begin
o.randomize();
$display("%b",o.vector);
end
end
endmodule