Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: i stuck on a random generator
Date: Thu, 1 Jan 2009 23:25:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 28
Message-ID: <gjjjce$3vf$1@fred.mathworks.com>
References: <gjjfrv$fb1$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1230852302 4079 172.30.248.37 (1 Jan 2009 23:25:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 1 Jan 2009 23:25:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1654984
Xref: news.mathworks.com comp.soft-sys.matlab:509445

SORRY TYPO IN PREVIOUS ONE. NOW CORRECTED!

> Hi
> 
> Im trying to create a random generator so i can place N charges in random positions from -1 to 1.
> 
> so far, i have:
> 
> N = user to enter number of charges,
> 
> % Position N charges randomly on R.
> R(1)=-1; % Boundary positions.
> R(N)=1;
> 
> % N*N will give enough positions for the N charges to be placed on.
> a=linspace(-1,1,N*N); 
> for i = 2:N-1
>     R(i) = a(round(rand(1)*(N*N)))
> end
> 
> Lets say we have 10 charges. 
> R(1) and R(10) are charges placed on the boundary.
> 
> the 8 charges in between give me the same random number for all 8 charges.
> 
> Can you help me please!
> Warm Regards
> Sid Hayes