Altera_Forum
Honored Contributor
12 years agoInitialize signal with random number
I'd like to intitialize one of my signals with a random number. The only way I know how to use random numbers in vhdl is with the UNIFORM statement in a testbench loop. Is there a way to assign a random number in an architecture block?
Right now I'm doing it the following way, but getting errors due to the shared variable.
shared variable pncomp_seed : std_logic_vector(width -1 downto 0);
begin
clk_wire <= clk;
output<= final_output_wire;
isvalid <= valid_wire;
-- Calculate seeds
process
variable internal_seed1,internal_seed2 : positive;
variable rand_num : real;
variable int_rand_num : integer;
begin
UNIFORM(internal_seed1,internal_seed2,rand_num);
int_rand_num := INTEGER(TRUNC(rand_num*256.0));
pncomp_seed := std_logic_vector(to_unsigned(int_rand_num,pncomp_seed'length));
end process;
seed_wire <= pncomp_seed;