I'm trying to randomly generate a point within a 10 kilometer radius of a point on the globe in R, and cannot figure out how to in a direct way. The goal is to have an arbitrary point on the globe with coordinates given in WGS84 coordinates, pick a random direction, then a random distance 0-10km and place a new point there. My current solution works, and relies on picking a random distance using runif, then using st_buffer to create a ring of that radius, subtracting the intersection of the ring with a slightly smaller ring to approximate a circle, and then using st_sample to generate a point on the ring. This works, but is incredibly slow, and I need to perform this operation millions of times in my program, so I need to find a more efficient method if possible. The overall goal is to replicate the DHS anonymization algorithm in R on a data set.
I have set up a working means of turning the generated random distances and angles into x and y coordinates in meters that can be added to a point's coordinates to displace it the correct way, but my sample is an sf data frame using WGS84, and the coordinates are therefore not in meters.here are some example coords
I'm not sure how to properly convert the points or translations without having issues involving the curvature of the Earth messing with the distances and angles.