Random points on a sphere in Golang.
If you generate latitude and longitude uniformly in the ranges [-90, 90]
and
[-180, 180]
you will get distributions biased towards the poles.
This package correctly picks points on a sphere, providing a uniform distribution visualized below.
Install with
$ go get -u github.com/mmcloughlin/spherand
Generate a geographical point with
lat, lng := spherand.Geographical()
You can also generate spherical coordinates with Spherical()
.
If you need to control the random source, use a generator
g := spherand.NewGenerator(rand.New(rand.NewSource(42)))
lat, lng := g.Geographical()
See go.dev for reference.
Generated with globe.