I'd like to select a random decimal between, say, .40 and .60. So .45 or .55 would be desired. .61 not. All ranges would be between 0 and 1.
I have googled and seem to be able to do this with integers using rand()*
but can't seem to get it quite right for decimals only.
1条答案
按热度按时间2q5ifsrm1#
The general form of generating a random number would be
min + rand() * (max - min)
. So, in your case: