Forum Discussion
Altera_Forum
Honored Contributor
13 years agoHi DAVE
I am trying to find the mean and variance for random generating function code shown below. I know how to calculate practically but not able to implement it can you please help me.. LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; USE IEEE.NUMERIC_STD.ALL; USE IEEE.STD_LOGIC_SIGNED.ALL; ENTITY random IS ------> Interface GENERIC (n : INTEGER := 16); -- Input bit width PORT( clk : IN STD_LOGIC; random_num : OUT STD_LOGIC_VECTOR(n-1 DOWNTO 0); random_sum: OUT STD_LOGIC_VECTOR(n-1 DOWNTO 0) ); END random; ARCHITECTURE Behavioral of random is BEGIN PROCESS(clk) VARIABLE rand_temp : STD_LOGIC_VECTOR(n-1 DOWNTO 0) := (n-1 => '1' , OTHERS => '0'); VARIABLE temp : STD_LOGIC := '0'; VARIABLE sum : STD_LOGIC_VECTOR(n-1 DOWNTO 0) :=( OTHERS => '0'); BEGIN IF(RISING_EDGE(clk)) THEN temp := rand_temp(n-1) XOR rand_temp(n-2); rand_temp(n-1 DOWNTO 1) := rand_temp(n-2 DOWNTO 0); rand_temp(0) := temp; sum := sum + rand_temp; END IF; random_num <= rand_temp; random_sum <= sum; END PROCESS; END; --ADI