Обсуждение: setseed accepts bad seeds
Why doesn't setseed complain when given a seed value outside of its expected range? The documentation claims that 0 -> 1 should be used, but shouldn't it actually be -1 -> 1 to get the full range of the seed? If passed a value outside this range you always get the same value which isn't going to produce a good random number stream. Kris Jurka
Kris Jurka <books@ejurka.com> 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
On Wed, 11 Apr 2007, Tom Lane wrote: > Kris Jurka <books@ejurka.com> 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
Kris Jurka <books@ejurka.com> writes:
> On Wed, 11 Apr 2007, Tom Lane wrote:
>> Kris Jurka <books@ejurka.com> 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
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
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 <bruce@momjian.us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com
+ If your life is a hard drive, Christ can be your backup. +
Kris Jurka <books@ejurka.com> 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
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 Jurka
Kris Jurka <books@ejurka.com> 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