Re: [BUGS] setseed accepts bad seeds
On Mon, 10 Mar 2008, Tom Lane wrote: I'd be inclined to leave the mapping alone and just insert a warning (or hard error) for inputs outside the range -1 to 1. Here's a patch that errors out for out of range values. Kris JurkaIndex: doc/src/sgml/func.sgml === RCS file: /projects/cvsroot/pgsql/doc/src/sgml/func.sgml,v retrieving revision 1.423 diff -c -r1.423 func.sgml *** doc/src/sgml/func.sgml 6 Mar 2008 18:49:32 - 1.423 --- doc/src/sgml/func.sgml 10 Mar 2008 06:11:55 - *** *** 828,834 row entryliteralfunctionsetseed/function(typedp/type)/literal/entry entrytypevoid/type/entry !entryset seed for subsequent literalrandom()/literal calls (value between 0 and 1.0)/entry entryliteralsetseed(0.54823)/literal/entry entry/entry /row --- 828,834 row entryliteralfunctionsetseed/function(typedp/type)/literal/entry entrytypevoid/type/entry !entryset seed for subsequent literalrandom()/literal calls (value between -1.0 and 1.0)/entry entryliteralsetseed(0.54823)/literal/entry entry/entry /row Index: src/backend/utils/adt/float.c === RCS file: /projects/cvsroot/pgsql/src/backend/utils/adt/float.c,v retrieving revision 1.153 diff -c -r1.153 float.c *** src/backend/utils/adt/float.c 1 Jan 2008 19:45:52 - 1.153 --- src/backend/utils/adt/float.c 10 Mar 2008 06:11:55 - *** *** 1684,1691 setseed(PG_FUNCTION_ARGS) { float8 seed = PG_GETARG_FLOAT8(0); ! int iseed = (int) (seed * MAX_RANDOM_VALUE); srandom((unsigned int) iseed); PG_RETURN_VOID(); --- 1684,1695 setseed(PG_FUNCTION_ARGS) { float8 seed = PG_GETARG_FLOAT8(0); ! 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(); Index: src/backend/utils/misc/guc.c === RCS file: /projects/cvsroot/pgsql/src/backend/utils/misc/guc.c,v retrieving revision 1.435 diff -c -r1.435 guc.c *** src/backend/utils/misc/guc.c10 Mar 2008 03:22:29 - 1.435 --- src/backend/utils/misc/guc.c10 Mar 2008 06:11:55 - *** *** 1849,1855 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 }, { --- 1849,1855 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE }, phony_random_seed, ! 0.5, -1.0, 1.0, assign_random_seed, show_random_seed }, { -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs
Re: [BUGS] setseed accepts bad seeds
Kris Jurka [EMAIL PROTECTED] writes: On Mon, 10 Mar 2008, Tom Lane wrote: I'd be inclined to leave the mapping alone and just insert a warning (or hard error) for inputs outside the range -1 to 1. Here's a patch that errors out for out of range values. Applied, thanks. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs
Re: [BUGS] setseed accepts bad seeds
Kris Jurka [EMAIL PROTECTED] writes: On Wed, 11 Apr 2007, Tom Lane wrote: It's not really possible to use it incorrectly, AFAICS. Any value you might pass to it will result in a specific new seed value. Nowhere is there any guarantee of what the mapping is, and it's obviously impossible to guarantee that the mapping is one-to-one, so any user assumptions about what a specific seed value might mean seem broken regardless. Then please consider this patch which checks the range and maps the provided value to the entire seed space. I'm still not very happy about this. It'll change the behavior of existing applications, in the service of no goal that I consider convincing. I'd be inclined to leave the mapping alone and just insert a warning (or hard error) for inputs outside the range -1 to 1. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs
Re: [BUGS] setseed accepts bad seeds
This has been saved for the 8.4 release: http://momjian.postgresql.org/cgi-bin/pgpatches_hold --- Kris Jurka wrote: On Wed, 11 Apr 2007, Tom Lane wrote: It's not really possible to use it incorrectly, AFAICS. Any value you might pass to it will result in a specific new seed value. Nowhere is there any guarantee of what the mapping is, and it's obviously impossible to guarantee that the mapping is one-to-one, so any user assumptions about what a specific seed value might mean seem broken regardless. Then please consider this patch which checks the range and maps the provided value to the entire seed space. Kris Jurka Content-Description: [ Attachment, skipping... ] ---(end of broadcast)--- TIP 7: You can help support the PostgreSQL project by donating at http://www.postgresql.org/about/donate -- Bruce Momjian [EMAIL PROTECTED] http://momjian.us EnterpriseDB http://www.enterprisedb.com + If your life is a hard drive, Christ can be your backup. + ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [BUGS] setseed accepts bad seeds
Kris Jurka [EMAIL PROTECTED] writes: Why doesn't setseed complain when given a seed value outside of its expected range? Why should it complain? The use of the value is totally unspecified anyway. regards, tom lane ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly
Re: [BUGS] setseed accepts bad seeds
On Wed, 11 Apr 2007, Tom Lane wrote: Kris Jurka [EMAIL PROTECTED] writes: Why doesn't setseed complain when given a seed value outside of its expected range? Why should it complain? The use of the value is totally unspecified anyway. Because the user is likely using it incorrectly. I'm not sure what you mean by totally unspecified. The documentation[1] states: set seed for subsequent random() calls (value between 0 and 1.0) When a user calls setseed(5), setseed(500), or setseed(-500) they get the same seed value each time which is surely not what they intended. At minimum I think it should raise a warning. Also I think that documentation should be corrected to indicate that vaules -1 to 1 are the correct seed value range or it should it should map 0-1 to the entire seed space, not just half of it as is currently done. The decision of which change to make is unclear because it's a change to either the call signature or to the generated values for a given user supplied seed. Kris Jurka [1] http://www.postgresql.org/docs/8.2/static/functions-math.html#FUNCTIONS-MATH-FUNC-TABLE ---(end of broadcast)--- TIP 6: explain analyze is your friend
Re: [BUGS] setseed accepts bad seeds
Kris Jurka [EMAIL PROTECTED] writes: On Wed, 11 Apr 2007, Tom Lane wrote: Kris Jurka [EMAIL PROTECTED] writes: Why doesn't setseed complain when given a seed value outside of its expected range? Why should it complain? The use of the value is totally unspecified anyway. Because the user is likely using it incorrectly. It's not really possible to use it incorrectly, AFAICS. Any value you might pass to it will result in a specific new seed value. Nowhere is there any guarantee of what the mapping is, and it's obviously impossible to guarantee that the mapping is one-to-one, so any user assumptions about what a specific seed value might mean seem broken regardless. regards, tom lane ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly
Re: [BUGS] setseed accepts bad seeds
On Wed, 11 Apr 2007, Tom Lane wrote: It's not really possible to use it incorrectly, AFAICS. Any value you might pass to it will result in a specific new seed value. Nowhere is there any guarantee of what the mapping is, and it's obviously impossible to guarantee that the mapping is one-to-one, so any user assumptions about what a specific seed value might mean seem broken regardless. Then please consider this patch which checks the range and maps the provided value to the entire seed space. Kris JurkaIndex: src/backend/utils/adt/float.c === RCS file: /projects/cvsroot/pgsql/src/backend/utils/adt/float.c,v retrieving revision 1.149 diff -c -r1.149 float.c *** src/backend/utils/adt/float.c 27 Feb 2007 23:48:08 - 1.149 --- src/backend/utils/adt/float.c 11 Apr 2007 18:48:42 - *** *** 1783,1790 setseed(PG_FUNCTION_ARGS) { float8 seed = PG_GETARG_FLOAT8(0); ! int iseed = (int) (seed * MAX_RANDOM_VALUE); srandom((unsigned int) iseed); PG_RETURN_VOID(); --- 1783,1800 setseed(PG_FUNCTION_ARGS) { float8 seed = PG_GETARG_FLOAT8(0); ! int iseed; ! ! if (seed 0 || seed 1) ! elog(WARNING, setseed parameter %f out of expected range [0,1], seed); ! ! /* !* map seed range from [0, 1] to [-1, 1] to get the !* full range of possible seed values. !*/ ! seed = 2 * (seed - 0.5); + iseed = (int) (seed * MAX_RANDOM_VALUE); srandom((unsigned int) iseed); PG_RETURN_VOID(); ---(end of broadcast)--- TIP 7: You can help support the PostgreSQL project by donating at http://www.postgresql.org/about/donate