glibc_random.vhdl 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. library work;
  5. use work.glibc_random_helpers.all;
  6. package glibc_random is
  7. function pseudorand(a: integer) return std_ulogic_vector;
  8. function pseudorand1 return std_ulogic;
  9. end package glibc_random;
  10. package body glibc_random is
  11. function pseudorand(a: integer) return std_ulogic_vector is
  12. variable tmp1, tmp2, tmp3, tmp4: std_ulogic_vector(31 downto 0);
  13. variable ret: std_ulogic_vector(63 downto 0);
  14. begin
  15. tmp1 := std_ulogic_vector(to_unsigned(random, 32));
  16. tmp2 := std_ulogic_vector(to_unsigned(random, 32));
  17. if a <= 32 then
  18. ret := tmp1 & tmp2;
  19. else
  20. tmp3 := std_ulogic_vector(to_unsigned(random, 32));
  21. tmp4 := std_ulogic_vector(to_unsigned(random, 32));
  22. ret := tmp1(15 downto 0) & tmp2(15 downto 0) & tmp3(15 downto 0) & tmp4(15 downto 0);
  23. end if;
  24. return ret((a-1) downto 0);
  25. end;
  26. function pseudorand1 return std_ulogic is
  27. variable tmp: std_ulogic_vector(31 downto 0);
  28. begin
  29. tmp := std_ulogic_vector(to_unsigned(random, 32));
  30. return tmp(0);
  31. end;
  32. end package body glibc_random;