Forum Discussion
Altera_Forum
Honored Contributor
13 years agoif its a constant, you can do whatever maths you want in the function call. So just have a generic called "SEED" or something that then does something inside the f_generate_unique_id function.
Here is an example that generates a random number for C_MYID and compiles fine.
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_misc.all;
use ieee.numeric_std.all;
entity rand_test is
generic
(
SEED : positive := 22553362
);
port
(
a : in std_logic;
b : out std_logic
);
end entity rand_test;
architecture test of rand_test is
function set_init_val return std_logic_vector is
use ieee.math_real.all; --for uniform procedure
variable rand : real;
variable seed1, seed2 : positive := SEED;
variable result : integer;
begin
uniform(seed1, seed2, rand);
result := integer(((rand - 0.5) *2.0) * real(integer'high)); --makes random range from integer'low to integer'high by making "rand" range -1 to +1
return std_logic_vector( to_signed(result, 32));
end function;
constant C_MYID : std_logic_vector := set_init_val;
begin
b <= a and and_reduce(C_MYID);
end test;