Guest
Can anyone please tell me how to generate random numbers in verilog
between 0 to 3 or any range such that the number generated earlier do
not repeat.
between 0 to 3 or any range such that the number generated earlier do
not repeat.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Do you know about $random?Can anyone please tell me how to generate random numbers in verilog
between 0 to 3 or any range such that the number generated earlier do
not repeat.
Can anyone please tell me how to generate random numbers in verilog
between 0 to 3 or any range such that the number generated earlier do
not repeat.
That's silly. If $random is random, then so is $random % N. ThereIt is easy to generate value in range such as 0-9. You can try ran_a =
$random() % 10. But it is hard to keep it not repeat. Systemverilog do
it well with constraint random feature.
Enchanter wrote:Can anyone please tell me how to generate random numbers in verilog
between 0 to 3 or any range such that the number generated earlier do
not repeat.
Stephen Williams <spamtrap@icarus.com> writes:It is easy to generate value in range such as 0-9. You can try ran_a =
$random() % 10. But it is hard to keep it not repeat. Systemverilog do
it well with constraint random feature.
Yes, I think you are missing the fact that the requester asked for aThat's silly. If $random is random, then so is $random % N. There
are caveats WRT the randomness of all 32 bits of the output from
$random, but for modeling purposes it's distributed well enough
that if you think $random%10 isn't random, then $random isn't either.
I wonder what aspect of SystemVerilog you believe makes better
random numbers from 0-9?
Or am I somehow misunderstanding the original request?
I believe you are misunderstanding the original request. The OP doesOr am I somehow misunderstanding the original request?
Steve, you can combine your two approaches to get a relatively quickOne way to implement something like this is to recognize that you are
not generating a random number. Instead, you are taking the numbers in
the range and generating them in a random order. So you could start
with an array containing the numbers in the range, and apply a
shuffling algorithm of some kind. For example, swap randomly chosen
elements a lot of times. Then read out the array in order to get your
numbers.
An alternate approach would be to keep track of which numbers you have
generated with an array of flags, and keep generating numbers until you
get one that you have not generated yet. This would get very slow for
the last few numbers in a large range. There are probably better
algorithms, but this is what comes to mind on quick thought.
Can anyone please tell me how to generate random numbers in verilog
between 0 to 3 or any range such that the number generated earlier do
not repeat.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Enchanter wrote:
It is easy to generate value in range such as 0-9. You can try ran_a =
$random() % 10. But it is hard to keep it not repeat. Systemverilog do
it well with constraint random feature.
That's silly. If $random is random, then so is $random % N. There
are caveats WRT the randomness of all 32 bits of the output from
$random, but for modeling purposes it's distributed well enough
that if you think $random%10 isn't random, then $random isn't either.
I wonder what aspect of SystemVerilog you believe makes better
random numbers from 0-9?
Or am I somehow misunderstanding the original request?
- --
Steve Williams "The woods are lovely, dark and deep.
steve at icarus.com But I have promises to keep,
http://www.icarus.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep."
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org
iD8DBQFE6yd6rPt1Sc2b3ikRAuJgAJwP/uXPzYAsca66K9qoggih3fN59gCfaOVp
Km3ifCdsBf2l8CinEfTbFD4=
=9Vcm
-----END PGP SIGNATURE-----
Does this request ask for a new list of random numbers that isn't the same
as the list you ran through simulation the last time?
nikhil_err@yahoo.co.in> wrote in message
news:1156248866.151336.248690@m79g2000cwm.googlegroups.com...
Can anyone please tell me how to generate random numbers in verilog
between 0 to 3 or any range such that the number generated earlier do
not repeat.
It will give you a random number in that range, if that is what youDo you think $dist_uniform(seed,start,end) will serve my purpose.
nikhil_err@yahoo.co.in wrote:
Do you think $dist_uniform(seed,start,end) will serve my purpose.
It will give you a random number in that range, if that is what you
want. It will not avoid repeating a number, since the numbers are
supposed to be random.
BTW, if you follow the suggestion of using $random % 4, this will not
actually give you values in the range 0:3. $random is officially
defined to return an integer, which is signed. And a negative signed
number will produce a negative modulo result. So you would get values
in the range -3:3 instead. You would need to force the number to be
treated as unsigned before the modulo. One easy way would be to use
{$random} % 4.
Well, pseudo-random *bits* actually... and you can use themMaximal LFSR with N bits would produce unrepeating string of
2^(N)-1 pseudo-random numbers.
I'm curious: does System Verilog stipulate the quality of the randomOn 29 Aug 2006 00:34:46 -0700, bazarnik@hotmail.com wrote:
Maximal LFSR with N bits would produce unrepeating string of
2^(N)-1 pseudo-random numbers.
Well, pseudo-random *bits* actually... and you can use them
to create (( (2^N)-1 ) / N) random NUMBERS each N bits wide.
If you use successive samples of an LFSR's shift register
in the hope of getting random numbers, you'll be disappointed:
they will be very highly correlated, for obvious reasons.
Can anyone please tell me how to generate random numbers in verilog
between 0 to 3 or any range such that the number generated earlier do
not repeat.