Skip to content
Snippets Groups Projects
Commit 3daedc06 authored by rhomeister's avatar rhomeister
Browse files

added random seed option to Geocoder::Calculations.random_point_near

parent 62212c8a
No related branches found
No related tags found
No related merge requests found
......@@ -237,11 +237,14 @@ module Geocoder
#
# * <tt>:units</tt> - <tt>:mi</tt> or <tt>:km</tt>
# Use Geocoder.configure(:units => ...) to configure default units.
# * <tt>:seed</tt> - The seed for the random number generator
def random_point_near(center, radius, options = {})
# set default options
options[:units] ||= Geocoder.config.units
random = Random.new(options[:seed] || Random.new_seed)
# convert to coordinate arrays
center = extract_coordinates(center)
......@@ -249,11 +252,11 @@ module Geocoder
max_degree_delta = 360.0 * (radius / earth_circumference)
# random bearing in radians
theta = 2 * Math::PI * rand
theta = 2 * Math::PI * random.rand
# random radius, use the square root to ensure a uniform
# distribution of points over the circle
r = Math.sqrt(rand) * max_degree_delta
r = Math.sqrt(random.rand) * max_degree_delta
delta_lat, delta_long = [r * Math.cos(theta), r * Math.sin(theta)]
[center[0] + delta_lat, center[1] + delta_long]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment