Hi,
Had this question is character a datatype in system verilog like in C? I saw that being used in a blog but when I used it to write code in edaplayground it is not being highlighted as keyword and giving error.
I am trying to randomize a string and was using array of char for that.
Here is my code:
class str_random;
string str;
rand int str_length;
rand char c;
constraint a1 { str_length inside {[6:9]};}
constraint a2 { c.size() == str_length;
foreach(c[i]) {
c[i] inside {[65:90]};
}
}
constraint a3 { solve str_length before c;}
function void post_randomize();
foreach(c[i]) begin
str = {str,string'(c[i])};
end
endfunction
endclass
module try;
str_random ss;
initial begin
ss = new();
ss.randomize();
$display(“the string is: %s”, ss.str);
end
endmodule
Error-[SE] Syntax error
Following verilog source has syntax error :
variable type is not user defined type
“testbench.sv”, 7: token is ‘c’
rand char c;
Thanks!