This uses #TurfJs polygon length function to calculate its circumference. The underlying sorting of the coordinates uses polar coordinates, since that is how they are being randomly generated. By first sorting over the degrees and the distances.
For most instances this is a pretty good estimate, though in some case a self-intersecting polygon can be created, which hints that there is a more optimized polygon.
Further this problem is a typical 'travelling salesman problem' which can be solved via various algorithms.
Though before considering such optimization issues, there is the main question if the randomly generated POI is even accessible to the public.
In the case one is a pedestrian, one could use #overpass to gather information if any #OpenStreetMap highways exist in the proximity to the POI and then find the one that is the closest and permissive to pedestrians. Then move the POI to that location.
This example only works if there is enough #OSM data at the location.
#mathematics #maths