Reply to Re: How to Gnerate a Random ID Number

Your name:

Reply:


Posted by Hugo Kornelis on 06/10/07 23:02

On Sat, 9 Jun 2007 21:19:25 +0000 (UTC), Erland Sommarskog wrote:

>Hugo Kornelis (hugo@perFact.REMOVETHIS.info.INVALID) writes:
>> On Sat, 9 Jun 2007 19:19:45 +0000 (UTC), Erland Sommarskog wrote:
>>
>>>chico_yallin@yahoo.com (chico_yallin@yahoo.com) writes:
>>>> I just wana make a random id number based on4 digits-for examples??
>>>
>>>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

Hi Erland,

Sorry, I should have been more clearer. I know that rand() is called
just once for a set-based query, returning the same value for each row.
In this case, the original poster wanted "a" random number, so I assumed
that one was enough - that's why I didn't understand why you preferred
newid().

>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.

Let's hope he chimes in, then.

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация