"Sid Hayes" <jhumata@aston.ac.uk> wrote in message <gjjjce$3vf$1@fred.mathworks.com>...
> 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:N1
> > 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

Is this what you're really attempting to do?
clc;
clear all;
answer = input('Enter number of charges:');
intAnswer = int32(answer);
% Get the random numbers, and sort them.
R = sort(2 * rand(intAnswer, 1)  1);
% Reassign the first and last elements so that
% they are on the boundaries of 1 and +1.
R(1) = 1;
R(intAnswer) = 1;
R % Display in command window
