MATLAB: How to generate a random number between two numbers,

random

how i get random number between two numbers , like i want random number between 20-150 like this , random, i know the max number and the minimum number and i want to matlab gave me a random number between the max and the minimum

Best Answer

The second example for rand() says this:
"In general, you can generate N random numbers in the interval (a,b) with the formula r = a + (b-a).*rand(N,1)."
With a=20 and b=150, you get what you want.
r = 20 + (150-20) .* rand(N,1)