4 ms·
> (rand() % (b - a)) + a; This is no longer uniform, because it introduces a bias towards small numbers.
by whyever 7y ago
> (rand() % (b - a)) + a;
This is no longer uniform, because it introduces a bias towards small numbers.
- sorenjan 7y agoYes, it's less than ideal. But like I said, often good enough. Sometimes you just want a simple way to get something approximately random, the actual distribution might be unimportant.