Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
11 years ago

Generating Random Byte values

Hi,

I am writing vhdl process that can generate random 8-bit(1 byte) values so that I can send that values to RAM which has 10 addresses. How can I do?

Thanks

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    if it is only for simulation, then you can use the uniform procedure from the math_real package. It generates random values in the range 0 - 1 that can then be used to scale other number. For example:

    
    use ieee.math_real.all;
    variable seed1, seed2 : positive;
    variable rand  : real;
    variable rand_int : integer;
    ...
    uniform(seed1, seed2, rand);
    rand_int := integer( trunc(256 * rand) ); 
    

    Remember, this code cannot be synthesised into an FPGA.