Hi Everyone
In the system verilog testbench how can I randomize an array??? In the example below I want 8 random variables for In_arr… how can I randomize the In_arr and use the same random variable in two different modules so that I can check how my checker is working for the given example…I tried writing it but it is not taking any inputs.
class stimulus;
rand logic [7:0] In_arr; //Declare random properties in class
constraint Limit { //Randomization controlled by constaint block
In_arr inside {[0:255]};
}
module top;
int b[8]= {1,2,3,4,5,6,7,8};
arbitrary
int t[8]= {In_arr};
int sum;
initial begin
for(int n = 0; n<8; ++n)begin
sum = 0;
for(int k = 0; k<=n; ++k)begin
sum += b[k]*t[n-k];
end
$display(n,, sum);
end
end
endmodule
And Also I have created another class from where I called the random variable in the top module. but the above program is not taking any of my inputs.
In reply to confused kid:
please use code tags to format your code. I have done that for you in the example above. Also, try to make your example correct syntactically, or place comments in the spots that are pseudo-code.
There is no special trick for randomizing an array of integers, you just declare it as rand, or you can call randomize on it directly.
class stimulus;
rand bit[7:0] t[8];
// there's no need to constrain the elements inside [0:255] because that is the
// only range of values the array elements can hold.
endclass
I do not know what you mean by " is not taking any of my inputs" what inputs?
I ran the simulation for 500 clock cycles every time its showing the similar output. I thought their was some mistake the way I’m randomizing the array. I want to generate 8 random variables in the same array and then use each element one after the other for 8 cycles of sum +=b[k]*t[n-k]. I hope you understood my question.
The output is the represent for sum which I’m calculating in both the modules and comparing it in the scoreboard.
Can you please give me method where I can randomize the array so that I can get values something like this t[8] = {25,36,88,96,75,64,78} or any other 8 bit values. so that I can use the same random values generated in my other modules too.