Originally Posted by

**Mush** Hi.

Basically I want to generate four random numbers in a certain interval, and they can't be equal (unlikely to happen, but just incase!).

So let's imagine, that, for example, that interval is [0.5,1]. I want to generate a number in that interval, use it in a calculation, then generate another number on that interval, and use that in the same calculation, etc.

So:

Code:

a1 = some number in [0.5,1]
operation on a1
a2 = some number in [0.5,1] not equal to a1
operation on a2
a3= some number in [0.5,1] not equal to a1 or a2
operation on a3
a4 = some number in [0.5,1] not equal to a1 or a2 or a3
operation on a4

I know that the 'rand' command generates a number on the interval [0 1]. Hrm. But I can't find any way to use that to meet my end.

Let the interval be (b,t) then somethink like:

Code:

function rv=RandIntvl(n,m,b,t)
%
% function to produce a matrix of size nxm of random numbers
% uniformly distributed on (b,t)
%
if t<=b
disp('error: b must be greater than t')
rv=[];
return
end
rv=rand(n,m);
rv=rv*(t-b)+b;

should do part of the trick (warning: untested code).

CB