Creating a Random Point Generator in VHDL

Joined
Apr 19, 2010
Messages
2
Reaction score
0
Hey, I am trying to create a Random Point generator with VHDL. I would like for points to generated randomly on the screen similar to the classic game Snake. Anybody have any ideas?
 
Joined
Mar 31, 2010
Messages
9
Reaction score
0
Below is an example of a function to generate a random standard logic vector. You would need to put it in a loop to generate a string of random numbers. If the seed is the same, every time you call this function it will return the same std logic vector. This is the problem I had... If you can think of a more elegant way to use the code below I'd be interested.

Code:
  function random_std_logic_vector (vector_size : integer)
    return std_logic_vector is
    variable seed1, seed2: positive;
    variable rand: real;
    variable int_rand: integer;
    variable stim: std_logic_vector(vector_size-1 downto 0);    
  begin
--    loop 
    UNIFORM(seed1, seed2, rand);
    -- get a random value of size vector_size
    rand := rand * real(vector_size);
    int_rand := integer(floor(rand));
    -- 2. convert to std_logic_vector
    stim := std_logic_vector(to_unsigned(int_rand, stim'LENGTH));
    seed1 := integer(real(seed1) * rand);      
--    end loop;
    return stim;
  end;

EDIT: ensure that you add:
use ieee.math_real.all
for this to work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top