Post by n***@yahoo.co.inCan 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 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?
Yes, I think you are missing the fact that the requester asked for a
list that didn't repeat. I would assume that the requestor wanted a
permutation and not just a list of random numbers in the range.
One inefficient way to get a permutation is to simply generate a list
and remove any duplicated numbers (ones you generated previously).
For small ranges of integers, i.e. 0..3, that can easily be done. If
you want a range of reals (floating point numbers), it is harder since
they are dense and there are lots of numbers between 0 and 3. On the
other hand, that also makes it unlikely that even just a simple list
of random numbers over the range will have any repeats.
So, the question is which problem the person wants solved--a
perumtation of integers or a list reals in the range 0..3 with no
duplicates. And, if the person needs a list of reals with no
duplicates, why isn't just a list of reals that might (but probably
doesn't) have duplicates isn't good enough?
There is also one last interpretation, which is the person wants a
random list that doesn't cycle (a true random list and not a
psuedo-random one). In that case, they need something completely
different than $random.
Hope this helps,
-Chris
*****************************************************************************
Chris Clark Internet : ***@world.std.com
Compiler Resources, Inc. Web Site : http://world.std.com/~compres
23 Bailey Rd voice : (508) 435-5016
Berlin, MA 01503 USA fax : (978) 838-0263 (24 hours)
------------------------------------------------------------------------------