Sorry for the necro add, but I needed an answer to the title of the post and found all the answers unsatisfactory for what I wanted (generating random Benford numbers) and I figured I should post an answer if anyone has the same issue as me.
First up, (this is mostly to address the post of the question, not the title) Benford's law doesn't apply to randomly selected numbers between two values. If you select a random number between 1 and X (where X is really large) then the odds of the number starting with 1 is the same as it starting with 8. What Benford's law is saying, you're more likely to naturally run into the number 13 than the number 83, that it's more likely for '13' to naturally describe something than '83'.
So, anyway, if you're interested in generating Benford-applicable numbers, what you want is:
- Generate a random number between 0.000 and 1.000
- Calculate 10 to the power of that number
- This value is the coefficient for a value in scientific notation
(you can verify that these steps will produce numbers Benford numbers, because random values between 0.000 and 0.301 will produce values between 1.0 and 2.0 - aka, the ~30.1% Benford predicts; this calculation is basically a reverse of the process Benford uses to estimate the start-digit-odds with Log10(X).)
From here, you can decide what exponentiation rules you want, depending on the scale of numbers you want (realistically, a pure Benford number generator is very rarely going to output anything larger than 3 or 4 digits.) If you want the most realistic simulation, you can simply make each exponential value 1/10th as likely as the one before it (this would be a pure Benford prediction method.) Or if you want a wide range of scope with more common larger numbers, simply choose an exponent at random (the starting digit would be Benford compliant, but not the scale of integer.)
For the pure option:
- Generate a second random number between 0.000 and 1.000
- Calculate 0-(Log10(1-RandomValue))
- Round this value down to the nearest integer
... for generated values between 0.0 and 0.899999..., this value will be 0. For values between 0.9 and 0.899999999...., this value will be 1. Etc - basically, it's a mathematical way of figuring out how many 9's are in the number before a non-9, aka, making each exponent value 1/10th as likely as the one before it.
The final answer is FirstValue x 10^SecondValue, with the whole thing rounded to an integer.