Improved random number generation in a range.

Change-Id: Ie53e0983b1bd42deae0e0346df0478b8c4fb5e9d
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
With the fix, the number of tries needed to get the expected accuracy is much less

Change-Id: I454e896ecac47a430f13b16bc2940959df78175b