A user on the postgis-users had an interesting question today: how to generate a geometry column in PostGIS with random points, linestrings, or polygons?
Random data is important for validating processing chains, analyses and reports. The best way to test a process is to feed it inputs!
Random points is pretty easy -- define an area of interest and then use the PostgreSQL random() function to create the X and Y values in that area.
Filling a target shape with random points is a common use case, and there's a special function just for that, ST_GeneratePoints(). Here we generate points inside a circle created with ST_Buffer().
If you have PostgreSQL 16, you can use the brand new random_normal() function to generate coordinates with a central tendency.
Linestrings are a little harder, because they involve more points, and aesthetically we like to avoid self-crossings of lines.