|
Posted by Gert-Jan Strik on 06/10/07 23:24
See inline
Hugo Kornelis wrote:
>
> On Sun, 10 Jun 2007 18:42:28 +0200, Gert-Jan Strik wrote:
>
> >[snip]
> >> >>checksum(newid()) is better than the rand() function.
> >> >
> >> > Hi Erland,
> >> >
> >> > What exactly makes checksum(newid()) better than rand() ?
> >>
> >> Here is a practical reason:
> >>
> >> select rand(), checksum(newid())
> >> from (select n = 1 union all select 2 union all select 4) as x
> >>
> >> I believe that there also issues with the randomness of rand(), although
> >> I don't remember the exact details. Steve Kass knows the full story.
> >
> >The rand() function is not random at all. It will give the next number
> >in from a repeatable sequence of numbers, based on the seed.
>
> Hi Gert-Jan,
>
> Isn't that what all random number generators do?
AFAIK they all create pseudo random numbers. I don't know if they all
procedure the repeatable results, based on the seed.
> And isn't newid() more or less the same (using a different seed and a
> different algorithm to compute the next value, but still computing some
> formula with a seed as input to get at a pseudo-random value?)
I doubt it. The newid() value has to be globally unique, which suggests
the function should never produce an 'old' value ever again.
When using rand(), you could expect the same values after a reseed, or
an SQL Server restart. The newid() function should not have such
behavior.
Gert-Jan
[Back to original message]
|