function [R] = randomGroups(n,m,bigRadius,groupRadius)
% randomGroups3(n,m,bigRadius,groupRadius) -- produces n random groups of m points each
% randomly scattered in the 2d plane
% defining the matrix - building the first (index) column

%Created by Jim Work, University of South Carolina, August 13th, 2003

M = [transpose(1:n*m)]

% A, S are arbitrary.  k is used throughout as a counter only.
A = groupRadius;
S= bigRadius;

% centers randomized
centerx = (rand(n,1)*S-S/2);
centery = (rand(n,1)*S-S/2);
centerz = (rand(n,1)*S-S/2);

%random x values

k= 0 ;
for j=1:n;
   for i=1:m;
      k=k+1;
      Column2(k) = centerx(j);
   end
end 
T = transpose(Column2);
M = [M T];

% random y values

k=0;
for j=1:n;
   for i=1:m;
      k=k+1;
      Column3(k) = centery(j);
   end
end   
T = transpose(Column3);
M = [M T];

% random z values

k=0;
for j=1:n;
   for i=1:m;
      k=k+1;
      Column4(k) = centerz(j);
   end
end   
T = transpose(Column4);
M = [M T];

% random points around that center
theta = rand(n*m,1)*360;
radius = rand(n*m,1)*A;
phi = rand(n*m,1)*180;

% modifier is an array that modifies the x and y and z values

k=0;
for i = 1:n*m;
   k = k+1;
   xmodifier(k)=(radius(k)*cos(theta(k))*sin(phi(k)));
end
xmodifier = transpose(xmodifier);

k = 0 ;
for i = 1:n*m;
   k = k+1;
   ymodifier(k)=(radius(k)*sin(theta(k))*sin(phi(k)));
end
ymodifier = transpose(ymodifier);

k = 0 ;
for i = 1:n*m;
   k = k+1;
   zmodifier(k)=(radius(k)*cos(phi(k)));
end
zmodifier = transpose(zmodifier);

goose = zeros(n*m, 1);
modifier = [goose xmodifier];
modifier = [modifier ymodifier];
modifier = [modifier zmodifier];

finalArray = (M + modifier);
R = finalArray





