Jeff Moden (6/9/2009)
vzurkowski (6/9/2009)
To "chose at random from 1,..,5" usually means to chose from 1,..,5 in such a way that any outcome has the same probability of being selected.Assuming T-SQL RAND() has good statistical properties (if someone knows of tests, please let me know), why would RAND(CHECKSUM(NEWID()) have good properties? (i.e.: why would it select a number uniformly distributed between 0 and 1 ?)
Why wouldn't it? You're giving it a random seed.
In fact, test it yourself. The following produces what would be expected of a random number generator...
[font="Courier New"] SELECT d.N, COUNT(*)
FROM (
SELECT TOP 1000000
ABS(CHECKSUM(NEWID())) % 5 + 1 AS N
FROM Master.dbo.SysColumns sc1
CROSS JOIN Master.dbo.SysColumns sc2
)d
GROUP BY d.N
ORDER BY d.N[/font]
--Jeff Moden
Change is inevitable... Change for the better is not.