我正在尝试找出一种用vivado在VHDL语言中生成随机值(伪随机就可以了)的方法(这意味着我不能使用math_real库)。
这些随机值将确定预分频器将运行的计数的数量,然后将依次生成用于应用程序的随机计时。
这意味着生成的值不需要有一个非常具体的值,因为我总是可以调整预分频器的运行速度。一般来说,我寻找的值在1000 - 10,000之间,但更大的值也可以。
我在网上找到了下面的代码,它实现了一个128位的xorshift,看起来确实工作得很好。唯一的问题是,这些值太大了,而且转换为整数是没有意义的,因为无符号整数的最大值是2^32。
代码如下:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity XORSHIFT_128 is
port (
CLK : in std_logic;
RESET : in std_logic;
OUTPUT : out std_logic_vector(127 downto 0)
);
end XORSHIFT_128;
architecture Behavioral of XORSHIFT_128 is
signal STATE : unsigned(127 downto 0) := to_unsigned(1, 128);
begin
OUTPUT <= std_logic_vector(STATE);
Update : process(CLK) is
variable tmp : unsigned(31 downto 0);
begin
if(rising_edge(CLK)) then
if(RESET = '1') then
STATE <= (others => '0');
end if;
tmp := (STATE(127 downto 96) xor (STATE(127 downto 96) sll 11));
STATE <= STATE(95 downto 0) &
((STATE(31 downto 0) xor (STATE(31 downto 0) srl 19)) xor (tmp xor (tmp srl 8)));
end if;
end process;
end Behavioral;在过去的几个小时里,我一直试图将这个128位的xorshift PRNG缩小到8位、16位甚至32位的PRNG,但每次我要么没有输出,要么我的模拟(测试平台)在一个周期后冻结。
我已经尝试了除法,但128位xorshift的输出太大了,这使得它成为一种非常笨拙的处理方式。
任何想法或指针都将非常受欢迎。
https://stackoverflow.com/questions/41387318
复制相似问题