MATLAB: Assigning a variable a random number between 0 and less than another variable

assigning valueless thanrange

I have to set a variable (deltaT) to any number from 0 to less than (deltaX^2)/2a. The value for (deltaX^2)/2a is based upon user input, so it isn't a set value. I am having trouble figuring out how to set deltaT to the range needed, because I am not sure how to input it to be from 0 to less than (deltaX^2)/2a. Any help would be appreciated!

Best Answer

  • rand() * (deltaX.^2)./(2*a)
    rand() will never be exactly 0 and will never be exactly 1 so this is a strict 0 < <