Random number between two numbers in IDL

Generating a random number, or an array of random numbers, between 0 and 1, in IDL is easy. Simply call upon RANDOMU. But how do you generate random numbers between two other numbers?

RANDOMU creates pseudo-random numbers between 0 and 1, and has a number of variables you can pass to it (but be careful when using it: Random Numbers Are…Uh, Not Random!). But what if you don’t want a random number between 0 and 1, and say between 2 and 5?


All you need to do is multiply by the range and add the start! So for example for a random number between 2 and 5:


Or say 10 random numbers between 4 and 10:


Told you it was easy.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.