<html><head></head><body><div class="ydp1e683bcyahoo-style-wrap" style="font-family:verdana, helvetica, sans-serif;font-size:16px;"><div></div>
        <div dir="ltr" data-setdir="false">Hi Regina,</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">The seed was an int generated from random(), so I'd expected to generate a different result every time. This didn't happen.</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Do I understand that if I omit the seed, I'll get a different point each time by default?</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Thanks,</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">   Brent <br></div><div><br></div>
        
        </div><div id="ydp281dcc1fyahoo_quoted_0556156328" class="ydp281dcc1fyahoo_quoted">
            <div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
                
                <div>
                    On Saturday, November 18, 2023 at 06:01:37 PM GMT+13, Regina Obe <lr@pcorp.us> wrote:
                </div>
                <div><br></div>
                <div><br></div>
                <div><div id="ydp281dcc1fyiv3900421105"><div><div class="ydp281dcc1fyiv3900421105WordSection1"><p class="ydp281dcc1fyiv3900421105MsoNormal">If you want the answer different each time, you don’t want to feed a seed to ST_GeneratePoints.  </p><p class="ydp281dcc1fyiv3900421105MsoNormal">The seed argument was added because some people wanted to generate the same answer for each run.</p><p class="ydp281dcc1fyiv3900421105MsoNormal">  </p><p class="ydp281dcc1fyiv3900421105MsoNormal"><a shape="rect" href="https://postgis.net/docs/ST_GeneratePoints.html" rel="nofollow" target="_blank">https://postgis.net/docs/ST_GeneratePoints.html</a>  (note the sentence: The optional <code><span style="font-size:10.0pt;">seed</span></code> is used to regenerate a deterministic sequence of points, and must be greater than zero.)</p><p class="ydp281dcc1fyiv3900421105MsoNormal">  </p><p class="ydp281dcc1fyiv3900421105MsoNormal">  </p><div style="border-width: medium medium medium 1.5pt; border-style: none none none solid; border-color: currentcolor currentcolor currentcolor blue; padding: 0in 0in 0in 4pt;"><div id="ydp281dcc1fyiv3900421105yqt47953" class="ydp281dcc1fyiv3900421105yqt6164020972"><div><div style="border-width: 1pt medium medium; border-style: solid none none; border-color: rgb(225, 225, 225) currentcolor currentcolor; padding: 3pt 0in 0in;"><p class="ydp281dcc1fyiv3900421105MsoNormal"><b>From:</b> postgis-users <postgis-users-bounces@lists.osgeo.org> <b>On Behalf Of </b>Brent Wood via postgis-users<br clear="none"><b>Sent:</b> Friday, November 17, 2023 11:53 PM<br clear="none"><b>To:</b> PostGIS Users Discussion <postgis-users@lists.osgeo.org><br clear="none"><b>Cc:</b> Brent Wood <pcreso@yahoo.com><br clear="none"><b>Subject:</b> [postgis-users] Generating new random points throughout an update</p></div></div><p class="ydp281dcc1fyiv3900421105MsoNormal">  </p><div><p class="ydp281dcc1fyiv3900421105MsoNormal">Hopefully someone can help with a problem I'm having.</p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">  </p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">I have a table with simple linestrings that I need to create a randomly modified version of.</p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">  </p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">The linestrings represent vessel tracks. I can identify a set of "similar" tracks & create a single "average" linestring that is somewhat representative.</p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">  </p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">Many of the records don't have a linestring, but for statistical purposes I need to assign a linestring to each - by creating a jittered version of the average linestring so they are not all identical.</p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">  </p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">The simplest approach I have tried is to use an update with ST_Project() given a random() distance & random() direction applied to each vertex in the average line.</p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">  </p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">I use the first two vertices with ST_Makeline(), then append a vertex for the third point, as in the SQL below. </p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">  </p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">My problem is that every new line is identical. From some Googled hints, I figure the optimiser has decided to run random() once & re-use the value instead of running the function for every iteration (but I could be wrong!).</p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">  </p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">Any suggestions as to how I can force a different random result for each record that is updated?</p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">I also tried using ST_GeneratePoints() in a buffer around each point, but need to use something like (random()::int as the seed, and this seems to do exactly the same - valid linestrings are generated, but they are identical, so I'm assuming the seed is not being recalculated for each record.</p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">  </p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">  </p></div><div><div><p class="ydp281dcc1fyiv3900421105MsoNormal"><i>update events<br clear="none">set jittered = ST_MakeLine(<br clear="none">                           (select ST_Project(<br clear="none">                                         ST_POINTN(std_track,1),<br clear="none">                                         (random()*5000),<br clear="none">                                         radians(random()*360))::geometry<br clear="none">                           from std_tow),<br clear="none">                  (select ST_Project(<br clear="none">                                         ST_PointN(std_track,2),<br clear="none">                                         (random()*5000),<br clear="none">                                           radians(random()*360))::geometry<br clear="none">                           from std_tow)<br clear="none">                  );</i></p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">  </p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">  </p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">Thanks,</p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">  </p></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">  Brent Wood</p></div></div></div><div><p class="ydp281dcc1fyiv3900421105MsoNormal">  </p></div></div></div></div></div></div>
            </div>
        </div></body></html>