I want to generate some uniform random numbers between [2E16, 5E20] in fortran90/95 or Python. I know that if "R" is a random number between zero and one (0<R<1), we can transform R to [A, B] as:
R = (b-a)*r + a.
But when I use this algorithm to generate some random numbers between [2E16, 5E20], most of generated random numbers are very close to 5E20. I know why this is occurred, it is because of that, the term B-A is approximately equal to B (because B is so bigger than A), and most of the generated random numbers are placed within the magnitude of B or B/10 (I mean it was very close to B).
How can I solve this problem?
One solution that I tried to apply is that, I split the [2E16, 5E20] interval into smaller intervals, such as:
[2e16, 2e17], [2e17, 2e18], [2e18, 2e19], [2e19, 2e20], [2e20, 5e20].
And I generated some random numbers between each of the above intervals.
Is there any other solutions? Is my solution correct?