Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Randomization_same number
Date: Sat, 7 Nov 2009 01:30:07 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 23
Message-ID: <hd2iiv$7pr$1@fred.mathworks.com>
References: <hd249a$im2$1@fred.mathworks.com> <hd265a$e8e$1@fred.mathworks.com> <hd26rr$q78$1@fred.mathworks.com> <hd2a11$974$1@fred.mathworks.com> <hd2cjh$evv$1@fred.mathworks.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257557407 7995 172.30.248.38 (7 Nov 2009 01:30:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 7 Nov 2009 01:30:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:583167


"D " <eclipse_dsotm@hotmail.com> wrote in message <hd2cjh$evv$1@fred.mathworks.com>...
> > So? Then be efficient in your code. Randperm is
> > fast. It takes little effort to test to see if elements
> > are consecutive. Use diff to do the test.
> > 
> > John
> 
> Thanks John. I do use the randperm function, but of course i have same trials in a row. I can find where (using diff as well), but still cannot solve the problem. 
> 
> I created a mask to get rid of all the numbers i've used, but i am not sure if it is efficient and worth trying -i am new in matlab. And besides, it doesn't work properly.
> 
> Thanks

So use randperm. Then set up a loop. Scan through
the sequence. If the ith element is equal to the previous
element, then swap it with the next element in the
sequence which is not equal to it. Continue this
operation until done. If you get to the end without
success, then wrap around to the beginning.

This will be fast.

John