Path: news.mathworks.com!not-for-mail
From: "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Drawing n random numbers from vector without replacement
Date: Thu, 8 Jul 2010 08:29:04 +0000 (UTC)
Organization: Universit&#228;t Heidelberg
Lines: 16
Message-ID: <i1428g$q8d$1@fred.mathworks.com>
References: <i140ri$1h$1@fred.mathworks.com>
Reply-To: "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1278577744 26893 172.30.248.37 (8 Jul 2010 08:29:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 8 Jul 2010 08:29:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869888
Xref: news.mathworks.com comp.soft-sys.matlab:651322

Dear Ulrik,

> Suppose I wish to draw 2 numbers at random without replacement from vector A
> A = [1 2 3 4 5 6 7 8 9 10]
> Which command will let me do this in Matlab?

See RANDPERM: Permute the vector randomly and draw the first 2 numbers.

If you need speed, see:
  http://www.mathworks.com/matlabcentral/fileexchange/27076
If your A is large, e.g. 1e7 elements, the random permutation wastes a remarkable chunk of time and memory. SHUFFLE in the "index" mode is more efficient:
  A = rand(1, 1e7);
  Index = Shuffle(1e7, 'index', 2);
  B = A(Index)

Good luck, Jan