# Misconceptions about random numbers in a range

I am currently working on a project the includes fitting. For the fitting I would like to try uniform random starting parameters. The possible fit parameters can lie in quite a large range, for example 10^-15 to 10^15 while others can lie in the range of -1 to 1. So quite diverse.

When I try to create random numbers that reflect this range like

Number = Rnd(0, 1) * (UpperLimit - LowerLimit) + LowerLimit


This approach however is pretty useless for the large range. Here pretty much all resulting random numbers are very large. I have yet to see a number smaller than 10^12 for the above range.

For the large range I can reduce the problem by using logarithms:

Number = 10^(Rnd(0, 1) * (Lg(UpperLimit) - Lg(LowerLimit)) + Lg(LowerLimit))


This now produces useful numbers over the whole logarithmic range yet it does not work for negative ranges or zero.

I think I haven't really understood the basic concepts. If you plot the large numbers in a point plot they seem very uniform, yet they only reflect the large values. Does that mean that small numbers are less likely to turn up?

The logarithmic numbers of course only look uniform in logarithmic scaling.

I can't be the first person to run unto these problems. How are random numbers usually chosen? In the first step I don't care about quality of randomness. I just want to reflect larger and smaller number ranges including negative and 0 randomly.

If I my explaination was to confusing please leave a comment and I will try to elaborate. As you may have noticed from the question I am note very well educated in statistics. So if you could keep it in Layman's terms I would be very grateful. Thanks in advance.

• To get a 10^12 in your first example, you would need to get a random number less than or equal to 0.001. Thus, you shouldn't expect to see numbers that small more than 1 out of a thousand.
– John
Aug 4, 2014 at 16:59
• Yes, that is my problem. But on this basis: Why is 0.001 less likely to pop up in the range (0,1) than say for example 0.64?
– Jens
Aug 4, 2014 at 17:04
• It isn't, numbers that look like 0.640 are more likely to pop up than numbers that look like 0.001. I'm not sure that I completely follow your question / the problem you're having. Your top code should work fine. What language are you using? Aug 4, 2014 at 17:07
• Yes the code itself works fine and does what it is supposed to, yet it still does not provide the anticipated results. I want to encounter numbers like 5.23*10^-6 as frequently as numbers like 1.54*10^13. Thinking about it I understand why my first comment was wrong. Yet it doesn't solve my problem. The logarithm code works fine for everything > 0 but I can't limit myself to this unfortunately.
– Jens
Aug 4, 2014 at 17:43
• @Jens The problem is that there are many more integers (just to illustrate the point) between 10^12 and 10^15 than there are between 0 and 10^12. In fact, there are about 999 times as many. So if you sampled each one with the same frequency (as you would with a uniform random distribution), then your results are exactly what I would expect.
– John
Aug 4, 2014 at 17:59

For the fitting I would like to try uniform random starting parameters

Note the word uniform there.

This approach however is pretty useless for the large range. Here pretty much all resulting random numbers are very large

This is a consequence of your desire for it to be uniform. If you choose numbers that are uniform on $(10^{-15}, 10^{15})$, then, perforce, about 99.9% of them exceed $10^{12}$.

If that doesn't reflect your desire, then your expressed wish for "uniform random starting parameters" doesn't reflect your actual desire in spite of the fact that you stated it explicitly. The word uniform means something; you must express your wishes with care.

How are random numbers usually chosen?

That depends on what you're trying to achieve; since your wishes as expressed in the question are self-contradictory, that's something to work out.

As you note, if the value was only positive, you seem to want something more like a uniform over the index (i.e. uniform in the logs), but you say you can't limit yourself to positive numbers.

You can't do a log scale across 0, of course. How should it behave in the neighborhood of zero? Are you after something that's maybe roughly uniform-ish near zero but more like uniform in the logs (with appropriate change of sign for negatives, presumably) when far from zero? Should it treat negative values (their sign aside) the same as positives in terms of how the scale works (sorry, I expressed that badly)?

• Ok I think I have misused the word uniform. As I said I never really learned about statistics in detail. What I wanted to say was kind of a uniform distribution (don't nail me on these ;-)) between large and small numbers. I'm thinking that I could generate random numbers from a distribution function that decayes exponentially with increasing x by means of the inverse function method. Has this any chance of success? The distribution does not need to be statistically perfect, as long as there are nearly as many small as large numbers, all's well.
– Jens
Aug 5, 2014 at 16:22
• The key is making a phrase like "nearly as many small as large numbers" precise enough that we're not talking about different things. But if you want something that decays exponentially (which won't be approximately uniform in the logs - even if we're only looking at values not too close to 0 - that's quite a different thing), you might consider something like perhaps a logistic distribution. Aug 5, 2014 at 21:18