From: Jos <x@y.z>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to generate different random numbers
Message-ID: <ef58601.5@webcrossing.raydaftYaTP>
Date: Fri, 1 Jun 2007 14:48:13 -0400
References: <ef58601.-1@webcrossing.raydaftYaTP> <ef58601.2@webcrossing.raydaftYaTP> <ef58601.3@webcrossing.raydaftYaTP> <ef58601.4@webcrossing.raydaftYaTP>
Lines: 34
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Xref: comp.soft-sys.matlab:412251

Cristina wrote:
> This doesn't address the exact desire for the random number
> generation but you could start here.
> Generate M random integers from 0 to N-1 via the following:
> X=mod(randperm(M),N);
> Then X contains a vector of random values of length M from 0 to
> N-1.
> They won't be all unique. For that I'd mix in the use of the
> command from matlab. I hope this helps. A histogram of this result
> shows a nice uniform distribution. To get a distribution from L to
> N
> just do new_X=X+L ;) for any value of L.
> Anyone who can add to this please feel free to comment,
> Cristina

R = randperm(M) ;
R = R(1:N) ;

will already produce uniformly N unique random numbers chosen from
the range of 1-M, without using MOD and UNIQUE.

and of course, one cannot draw N unique numbers between 1 and M if N
> M ...