Skip to content

Commit 23c356c

Browse files
committed
Document and enforce that the usable range of setseed() arguments is
-1 to 1, not 0 to 1. The actual behavior for values within this range does not change. Kris Jurka
1 parent bfce56e commit 23c356c

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

doc/src/sgml/func.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.423 2008/03/06 18:49:32 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.424 2008/03/10 12:39:22 tgl Exp $ -->
22

33
<chapter id="functions">
44
<title>Functions and Operators</title>
@@ -828,7 +828,7 @@
828828
<row>
829829
<entry><literal><function>setseed</function>(<type>dp</type>)</literal></entry>
830830
<entry><type>void</type></entry>
831-
<entry>set seed for subsequent <literal>random()</literal> calls (value between 0 and 1.0)</entry>
831+
<entry>set seed for subsequent <literal>random()</literal> calls (value between -1.0 and 1.0)</entry>
832832
<entry><literal>setseed(0.54823)</literal></entry>
833833
<entry></entry>
834834
</row>

doc/src/sgml/ref/set.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/set.sgml,v 1.91 2007/09/11 00:06:41 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/set.sgml,v 1.92 2008/03/10 12:39:22 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -166,7 +166,7 @@ SET [ SESSION | LOCAL ] TIME ZONE { <replaceable class="PARAMETER">timezone</rep
166166
<para>
167167
Sets the internal seed for the random number generator (the
168168
function <function>random</function>). Allowed values are
169-
floating-point numbers between 0 and 1, which are then
169+
floating-point numbers between -1 and 1, which are then
170170
multiplied by 2<superscript>31</>-1.
171171
</para>
172172

src/backend/utils/adt/float.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.153 2008/01/01 19:45:52 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.154 2008/03/10 12:39:22 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1684,8 +1684,12 @@ Datum
16841684
setseed(PG_FUNCTION_ARGS)
16851685
{
16861686
float8 seed = PG_GETARG_FLOAT8(0);
1687-
int iseed = (int) (seed * MAX_RANDOM_VALUE);
1687+
int iseed;
16881688

1689+
if (seed < -1 || seed > 1)
1690+
elog(ERROR, "setseed parameter %f out of range [-1,1]", seed);
1691+
1692+
iseed = (int) (seed * MAX_RANDOM_VALUE);
16891693
srandom((unsigned int) iseed);
16901694

16911695
PG_RETURN_VOID();

src/backend/utils/misc/guc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.435 2008/03/10 03:22:29 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.436 2008/03/10 12:39:23 tgl Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -1849,7 +1849,7 @@ static struct config_real ConfigureNamesReal[] =
18491849
GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
18501850
},
18511851
&phony_random_seed,
1852-
0.5, 0.0, 1.0, assign_random_seed, show_random_seed
1852+
0.0, -1.0, 1.0, assign_random_seed, show_random_seed
18531853
},
18541854

18551855
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy