From: Jos <x@y.z>
Path: news.mathworks.com!newsfeed-00.mathworks.com!webcrossing
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
NNTP-Posting-Host: 84.81.76.244
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Xref: news.mathworks.com 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
> UNIQUE
> 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
>
...

But
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 ...

Jos