Path: news.mathworks.com!newsfeed-00.mathworks.com!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!news-2.dfn.de!news.dfn.de!feeder.erje.net!newsfeed.straub-nv.de!feeder.eternal-september.org!eternal-september.org!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: array with random not repeated numbers
Date: Tue, 10 Nov 2009 18:04:48 -0600
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <hdcv34$sat$2@news.eternal-september.org>
References: <hdco0i$1kk$1@fred.mathworks.com> <45a8dd1f-8806-4903-ac8f-6a25382539f0@j19g2000vbi.googlegroups.com> <hdcu5e$mh4$1@fred.mathworks.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.eternal-september.org U2FsdGVkX1/xfTPrTwuOsSb989c1yy5K6VwDZOP4xL5uoiKn30eLury0hRyYqaLiHJ5vCDQLklHsZO1xjyptYX9j9Y4JqCrUZaSN48DzqDGyl9vgfv/mE91OOUxRCiRwSMJHKvMwxFMwYELEhHS2vQ==
X-Complaints-To: abuse@eternal-september.org
NNTP-Posting-Date: Wed, 11 Nov 2009 00:04:53 +0000 (UTC)
In-Reply-To: <HIDDEN>
X-Auth-Sender: U2FsdGVkX18zrHEB+VSLrIr04M6pkUDMIdVdpRoB0C4=
Cancel-Lock: sha1:wZXMcGHOGYZaH8daxljHeJrEK+I=
User-Agent: Thunderbird 2.0.0.23 (Windows/20090812)
Xref: news.mathworks.com comp.soft-sys.matlab:584015

Patrick Diviacco wrote:
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <45a8dd1f-8806-4903-ac8f-6a25382539f0@j19g2000vbi.googlegroups.com>...
>> On Nov 10, 5:04?pm, "Patrick Diviacco" <patrick.divia...@gmail.com>
>> wrote:
>>> hi,
>>>
>>> how can I generate an array with random numbers (given a min and max) ?
>>> Important: they have to be not repeated.
>>>
>>> thanks
>> -----------------------------------------------------------
>> Did you see the rand() function?
>> So how about something like this
>> randomArray = minValue + (maxValue-MinValue)*rand(rows, columns);
> 
> 
> Is this code avoiding duplicates ?

No, but odds are pretty good unless the number you're asking for is very 
high or the the range very constricted.

You can, of course, run a rejection/regeneration phase after the initial 
generation.

--