1

This is a test-bench, and I have these signals:

signal  DATA_INPUT  :std_logic_vector(0 to  31);
signal  rand_num    :integer;

I am trying to put random numbers into this 32bit signal by this:

DATA_INPUT  <=  std_logic_vector(to_unsigned(rand_num, 32));

My question is, I need numbers more than 31bits but when the random numbers goes above this number: 2147483647 which is INTEGER'high, I am getting this error:

near "4294967295": (vcom-119) Integer value exceeds INTEGER'high.
# ** Error: tb.vhd: (vcom-1144) Value -1 (of type
std.STANDARD.NATURAL) is out of range 0 to 2147483647.

I tried to modify the TO_UNSIGNED() function and change the NATURAL input to something else but nothing.

Here is the TO_UNSIGNED function from IEEE and RANDOOM GENERATOR process:

function TO_UNSIGNED(ARG, SIZE: NATURAL) return UNSIGNED is
        variable RESULT: UNSIGNED (SIZE-1 downto 0);
        variable i_val: NATURAl := ARG;
        begin
            if (SIZE < 1) then return NAU; end if;
            for i in 0 to RESULT'left loop
            if (i_val MOD 2) = 0 then
               RESULT(i) := '0';
            else RESULT(i) := '1';
              end if;
            i_val := i_val/2;
            end loop;
            if not(i_val=0) then
            assert NO_WARNING 
            report "numeric_std.TO_UNSIGNED : vector truncated"
            severity WARNING;
            end if;
        return RESULT;
    end TO_UNSIGNED;

Random generator:

process
    variable seed1, seed2   :positive;
    variable rand   :real;
    variable    range_of_rand   :real:= 46340.0;
begin
    uniform(seed1, seed2, rand);
    rand_num <= integer(rand*range_of_rand);
    wait for 1 ns;
end process;
  • You might want to look into OSVVM as this has a RandomPkg that can generate random SLV of any length, as well as using different (non-uniform) distributions. – Tricky Apr 24 '19 at 12:14
  • Jim Lewis' [OSVVM](https://github.com/OSVVM/OSVVM) package [RandomPkg](https://github.com/OSVVM/OSVVM/blob/master/RandomPkg.vhd) which the [RandomPkg User's Guide](https://github.com/OSVVM/OSVVM/blob/master/doc/RandomPkg_user_guide.pdf) tells us does Large Vector Randomization (section 6) using `impure function RandUnsigned (Size : natural) return unsigned` which in your case would provide two calls to `impure function Uniform (Min, Max : integer) return integer` using a Scale function to constrain a random real to an integer that's length safe for a natural. –  Apr 24 '19 at 17:36

1 Answers1

0

You can make a new,bigger random number by combining two.

The simplest solution is to convert two random integers to vectors and then concatenate until you get the number of bits you need. This gives you 64 bits:

DATA_INPUT <= std_logic_vector(to_unsigned(rand_num, 32)) & std_logic_vector(to_unsigned(rand_num, 32));
Oldfart
  • 6,104
  • 2
  • 13
  • 15