Monday, August 12, 2013

Unique and non-periodic random number in vhdl



Below is the function for unique and non-periodic random number generation in VHDL.

 shared variable seed1:integer:=844396720; -- uniform procedure seed1  
 shared variable seed2:integer:=821616997; -- uniform procedure seed2  
   
 impure function RANDOM_NUM_GEN(constant lower_value : in integer;  
 constant upper_value : in integer ) return integer is  
 variable result : integer;  
 variable tmp_real : real; -- return value from uniform procedure --  
 begin  
 uniform(seed1,seed2,tmp_real);  
 -- generates rand no. inside busWidth limit --  
 result :=integer(trunc((tmp_real * real(upper_value - lower_value)) + real(lower_value)));  
 return result;  
 end RANDOM_NUM_GEN;  

Usage :-

RANDOM_NUM_GEN (10,24566)
This will generate unique and non-periodic random numbers from 10 to 24566 .

No comments:

Post a Comment