D
Deepu
Guest
Hi All,
I am trying to generate numbers using a function which when called
generates a random number but not to repeat the same number again with
every call.
Code looks like:
reg [15:0] unique_random_number[];
int number_count;
initial begin
unique_random_number = new[9999];
number_count = 0;
end
// Function Calls
unique_random_number(0,30); // 1st Call
unique_random_number(0,30); // 2nd Call
unique_random_number(0,30); // 3rd Call
unique_random_number(0,30); // 4th Call
and so on...
unique_random_number(0,30); // 29th Call
unique_random_number(0,30); // 30th Call
unique_random_number(0,30); // 31st Call
function automatic int unique_random_number(
input int start =
16'd0,
input int end =
16'd10
);
int number;
begin
number = $urandom_range(start,end);
unique_random_number[++number_count] = number;
if (number_count > 9999)
begin
error ("Number assignment not correct");
$finish(2);
end
for (int count = 1; count < number_count; count = count + 1)
begin
if (unique_random_number[count] == number)
begin
number = unique_random_number();
end
end
$display ("[%0d]: +++ [unique_random_number] Unique Number :
%0d +++", $time, number);
unique_random_number = number;
end
endfunction // int
I get an message like:
ncsim: *W,RTSDAD (***): SystemVerilog dynamic array index 9999 does
not exist, 9999 items are in the dynamic array.
Please provide me some help on this..
I am trying to generate numbers using a function which when called
generates a random number but not to repeat the same number again with
every call.
Code looks like:
reg [15:0] unique_random_number[];
int number_count;
initial begin
unique_random_number = new[9999];
number_count = 0;
end
// Function Calls
unique_random_number(0,30); // 1st Call
unique_random_number(0,30); // 2nd Call
unique_random_number(0,30); // 3rd Call
unique_random_number(0,30); // 4th Call
and so on...
unique_random_number(0,30); // 29th Call
unique_random_number(0,30); // 30th Call
unique_random_number(0,30); // 31st Call
function automatic int unique_random_number(
input int start =
16'd0,
input int end =
16'd10
);
int number;
begin
number = $urandom_range(start,end);
unique_random_number[++number_count] = number;
if (number_count > 9999)
begin
error ("Number assignment not correct");
$finish(2);
end
for (int count = 1; count < number_count; count = count + 1)
begin
if (unique_random_number[count] == number)
begin
number = unique_random_number();
end
end
$display ("[%0d]: +++ [unique_random_number] Unique Number :
%0d +++", $time, number);
unique_random_number = number;
end
endfunction // int
I get an message like:
ncsim: *W,RTSDAD (***): SystemVerilog dynamic array index 9999 does
not exist, 9999 items are in the dynamic array.
Please provide me some help on this..