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
This commit is contained in:
parent
bfce56eea4
commit
23c356ccec
@ -1,4 +1,4 @@
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.423 2008/03/06 18:49:32 momjian Exp $ -->
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.424 2008/03/10 12:39:22 tgl Exp $ -->
|
||||
|
||||
<chapter id="functions">
|
||||
<title>Functions and Operators</title>
|
||||
@ -828,7 +828,7 @@
|
||||
<row>
|
||||
<entry><literal><function>setseed</function>(<type>dp</type>)</literal></entry>
|
||||
<entry><type>void</type></entry>
|
||||
<entry>set seed for subsequent <literal>random()</literal> calls (value between 0 and 1.0)</entry>
|
||||
<entry>set seed for subsequent <literal>random()</literal> calls (value between -1.0 and 1.0)</entry>
|
||||
<entry><literal>setseed(0.54823)</literal></entry>
|
||||
<entry></entry>
|
||||
</row>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/set.sgml,v 1.91 2007/09/11 00:06:41 tgl Exp $
|
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/set.sgml,v 1.92 2008/03/10 12:39:22 tgl Exp $
|
||||
PostgreSQL documentation
|
||||
-->
|
||||
|
||||
@ -166,7 +166,7 @@ SET [ SESSION | LOCAL ] TIME ZONE { <replaceable class="PARAMETER">timezone</rep
|
||||
<para>
|
||||
Sets the internal seed for the random number generator (the
|
||||
function <function>random</function>). Allowed values are
|
||||
floating-point numbers between 0 and 1, which are then
|
||||
floating-point numbers between -1 and 1, which are then
|
||||
multiplied by 2<superscript>31</>-1.
|
||||
</para>
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.153 2008/01/01 19:45:52 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.154 2008/03/10 12:39:22 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -1684,8 +1684,12 @@ Datum
|
||||
setseed(PG_FUNCTION_ARGS)
|
||||
{
|
||||
float8 seed = PG_GETARG_FLOAT8(0);
|
||||
int iseed = (int) (seed * MAX_RANDOM_VALUE);
|
||||
int iseed;
|
||||
|
||||
if (seed < -1 || seed > 1)
|
||||
elog(ERROR, "setseed parameter %f out of range [-1,1]", seed);
|
||||
|
||||
iseed = (int) (seed * MAX_RANDOM_VALUE);
|
||||
srandom((unsigned int) iseed);
|
||||
|
||||
PG_RETURN_VOID();
|
||||
|
@ -10,7 +10,7 @@
|
||||
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.435 2008/03/10 03:22:29 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.436 2008/03/10 12:39:23 tgl Exp $
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
*/
|
||||
@ -1849,7 +1849,7 @@ static struct config_real ConfigureNamesReal[] =
|
||||
GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
|
||||
},
|
||||
&phony_random_seed,
|
||||
0.5, 0.0, 1.0, assign_random_seed, show_random_seed
|
||||
0.0, -1.0, 1.0, assign_random_seed, show_random_seed
|
||||
},
|
||||
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user