
subroutine Sphere( xc, yc, zc, bondlength, xn, yn, zn, Seed )

implicit none

! This subroutine randomly places a bead on the surface of a sphere
! with a radius of bondlength and center xc, yc, zc.  The coordinates
! of the new bead are xn, yn, zn.

real, intent(in)								:: xc, yc, zc
real, intent(in)								:: bondlength
real, intent(out)								:: xn, yn, zn
integer, intent(inout)							:: Seed
real, external									:: ran2

! Local Variables

real											:: a
real, dimension(3)								:: V

V(1) = 2.0 * ran2(Seed)	- 1.0
V(2) = 2.0 * ran2(Seed)	- 1.0

a = V(1) * V(1) + V(2) * V(2)

do while ( a > 1.0 )
	V(1) = 2.0 * ran2(Seed)	- 1.0
	V(2) = 2.0 * ran2(Seed)	- 1.0
	a = V(1) * V(1) + V(2) * V(2)
end do

V(3) = 1 - 2.0 * a

a = sqrt( 1 - a )

V(1) = 2.0 * a * V(1)
V(2) = 2.0 * a * V(2)

xn = xc + bondlength * V(1)
yn = yc + bondlength * V(2)
zn = zc + bondlength * V(3)

return 

end	subroutine Sphere





