Reputation: 2070
I want to generate a random number using uniform(). The maximum value must be equal to the maximum value of a N bit integer.
So I need to generate the value of a binary number with n '1's
Thank you
Upvotes: 0
Views: 518
Reputation: 996
uniform gives you a real number ranging from 0.0 to 1.0. You need to scale it to fit the desired value range and optionally convert it into a std_logic_vector.
For example for a N bit target value:
uniform(seed1, seed2, rand);
rand_int := integer(floor(rand*2.0**N));
sig <= std_logic_vector(to_unsigned(rand_int,N));
Upvotes: 1