
While this algorithm is fun in its own right, for some people and some places it can create unreasonable destinations (for instance, more than half of the locations for most Manhattanites
end up in the ocean, and most of the locations for the rest of the Manhattanites end up in Jersey). With this problem in mind, I've generalized the algorithm to give a random destination within any given parallelogram of any size. Follow xkcd's algorithm until you get to the point where you have two decimals, 0.xxxxxx... and 0.yyyyyy..., which we'll call n and m, respectively . Now, if A is the south-western point of the parallelogram, B is the north-western point, and C is the south-eastern point, then your latitude is given by (latitude of A + n(latitude of B - latitude of A) + m(latitude of C - latitude of A)), and your longitude is given by (longitude of A + n(longitude of B - longitude of A) + m(longitude of C - longitude of A)). Happy Hashing!
P.S. xkcd's algorithm is a special case of my algorithm, where the parallelogram is a square whose sides are 1 degree long and whose corners are at integer degrees.
0 comments:
Post a Comment