Forum Discussion
Altera_Forum
Honored Contributor
11 years ago --- Quote Start --- Thank you for your reply. I have read the errors and corrected them, the code is compiling. Do you know how to generate random numbers to inputs and outputs instead if fixed values? Kind regards, Deadman --- Quote End --- There are two ways. 1. If you need synthesisable pseudo random number, then google linear feedback shift register (LFSR). 2. For simulation only, the ieee.math_real package has a procedure called "uniform" that generates pseudo random real values between 0.0 and 1.0. You can use these to scale any value you want. For example, a rand_int procedure in my personal testbench tools package:
procedure rand_int( variable seed1, seed2 : inout positive; min, max : in integer; result : out integer) is
variable rand : real;
variable val_range : real;
begin
assert (max >= min) report "Rand_int: Range Error" severity Failure;
uniform(seed1, seed2, rand);
val_range := real(Max - Min + 1);
result := integer( trunc(rand * val_range )) + min;
end procedure;