Merge pull request #3664 from eumiro/consolidate-random

Consolidate usage of random module
This commit is contained in:
Sarah Hoffmann
2025-03-06 17:52:19 +01:00
committed by GitHub
2 changed files with 7 additions and 6 deletions

View File

@@ -28,9 +28,11 @@ class PlaceColumn:
assert 'osm_type' in self.columns, "osm column missing" assert 'osm_type' in self.columns, "osm column missing"
if force_name and 'name' not in self.columns: if force_name and 'name' not in self.columns:
self._add_hstore('name', 'name', self._add_hstore(
''.join(random.choice(string.printable) 'name',
for _ in range(int(random.random()*30)))) 'name',
''.join(random.choices(string.printable, k=random.randrange(30))),
)
return self return self
@@ -104,7 +106,7 @@ class PlaceColumn:
if self.columns['osm_type'] == 'N' and self.geometry is None: if self.columns['osm_type'] == 'N' and self.geometry is None:
pt = self.context.osm.grid_node(self.columns['osm_id']) pt = self.context.osm.grid_node(self.columns['osm_id'])
if pt is None: if pt is None:
pt = (random.random()*360 - 180, random.random()*180 - 90) pt = (random.uniform(-180, 180), random.uniform(-90, 90))
self.geometry = "ST_SetSRID(ST_Point(%f, %f), 4326)" % pt self.geometry = "ST_SetSRID(ST_Point(%f, %f), 4326)" % pt
else: else:

View File

@@ -41,8 +41,7 @@ def write_opl_file(opl, grid):
if line.startswith('n') and line.find(' x') < 0: if line.startswith('n') and line.find(' x') < 0:
coord = grid.grid_node(int(line[1:].split(' ')[0])) coord = grid.grid_node(int(line[1:].split(' ')[0]))
if coord is None: if coord is None:
coord = (random.random() * 360 - 180, coord = (random.uniform(-180, 180), random.uniform(-90, 90))
random.random() * 180 - 90)
line += " x%f y%f" % coord line += " x%f y%f" % coord
fd.write(line.encode('utf-8')) fd.write(line.encode('utf-8'))
fd.write(b'\n') fd.write(b'\n')