Reputation:
I know there are similar questions.
But mine has different settings.
rand()
srand()
to take a seed from user inputI don't know if it's possible to get uniformly distributed random numbers, do I have to use the random
library?
Upvotes: 1
Views: 92
Reputation: 881223
The C++ standard mostly defers to the C standard when it comes to the heritage functions like rand()
and srand()
.
Unfortunately, there is nothing in the C standard about rand()
delivering uniform distribution. In fact, it states in a footnote (my emphasis):
There are no guarantees as to the quality of the random sequence produced and some implementations are known to produce sequences with distressingly non-random low-order bits. Applications with particular requirements should use a generator that is known to be sufficient for their needs.
If you want specific properties for your random numbers, you really should be using the C++ stuff in <random>
(yes, I know you appear to have discounted that but you may have to make a trade-off: either use them or have no guarantee of a specific distribution).
Upvotes: 1