]> git.openstreetmap.org Git - nominatim.git/commitdiff
Consolidate usage of random module
authorMiroslav Šedivý <6774676+eumiro@users.noreply.github.com>
Tue, 4 Mar 2025 19:01:47 +0000 (20:01 +0100)
committerMiroslav Šedivý <6774676+eumiro@users.noreply.github.com>
Wed, 5 Mar 2025 18:38:28 +0000 (19:38 +0100)
test/bdd/steps/place_inserter.py
test/bdd/steps/steps_osm_data.py

index c033ac17f008ce3bc46237815795a5dccbd8e060..bd6c47df184d4a5b4586d5e801c264b5cbb54c7f 100644 (file)
@@ -28,9 +28,11 @@ class PlaceColumn:
         assert 'osm_type' in self.columns, "osm column missing"
 
         if force_name and 'name' not in self.columns:
-            self._add_hstore('name', 'name',
-                             ''.join(random.choice(string.printable)
-                                     for _ in range(int(random.random()*30))))
+            self._add_hstore(
+                'name',
+                'name',
+                ''.join(random.choices(string.printable, k=random.randrange(30))),
+            )
 
         return self
 
@@ -104,7 +106,7 @@ class PlaceColumn:
         if self.columns['osm_type'] == 'N' and self.geometry is None:
             pt = self.context.osm.grid_node(self.columns['osm_id'])
             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
         else:
index 70cf1515c65c738c6f908935982a5fe943fc1c0d..e9c8ebe42f70f47aaaf39f24b5234f119acdaf2e 100644 (file)
@@ -41,8 +41,7 @@ def write_opl_file(opl, grid):
             if line.startswith('n') and line.find(' x') < 0:
                 coord = grid.grid_node(int(line[1:].split(' ')[0]))
                 if coord is None:
-                    coord = (random.random() * 360 - 180,
-                             random.random() * 180 - 90)
+                    coord = (random.uniform(-180, 180), random.uniform(-90, 90))
                 line += " x%f y%f" % coord
             fd.write(line.encode('utf-8'))
             fd.write(b'\n')