dbTalk Databases Forums  

How to Gnerate a Random ID Number

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss How to Gnerate a Random ID Number in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Bob Quintal
 
Posts: n/a

Default Re: How to Gnerate a Random ID Number - 06-09-2007 , 05:44 AM






"chico_yallin (AT) yahoo (DOT) com" <chico_yallin (AT) yahoo (DOT) com> wrote in
news:1181388231.643515.94630 (AT) k79g2000hse (DOT) googlegroups.com:

Quote:
I just wana make a random id number based on4 digits-for
examples??

Thanks in Advance

Ch.Yallin


see the help files on the rnd() function.


--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com



Reply With Quote
  #2  
Old   
chico_yallin@yahoo.com
 
Posts: n/a

Default How to Gnerate a Random ID Number - 06-09-2007 , 06:23 AM






I just wana make a random id number based on4 digits-for examples??

Thanks in Advance

Ch.Yallin


Reply With Quote
  #3  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: How to Gnerate a Random ID Number - 06-09-2007 , 02:19 PM



chico_yallin (AT) yahoo (DOT) com (chico_yallin (AT) yahoo (DOT) com) writes:
Quote:
I just wana make a random id number based on4 digits-for examples??
checksum(newid()) is better than the rand() function.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #4  
Old   
Bob Quintal
 
Posts: n/a

Default Re: How to Gnerate a Random ID Number - 06-09-2007 , 03:04 PM



Erland Sommarskog <esquel (AT) sommarskog (DOT) se> wrote in
news:Xns994AD933293B9Yazorman (AT) 127 (DOT) 0.0.1:

Quote:
chico_yallin (AT) yahoo (DOT) com (chico_yallin (AT) yahoo (DOT) com) writes:
I just wana make a random id number based on4 digits-for
examples??

checksum(newid()) is better than the rand() function.

Please provide instructions on the use of these functions in MS-
Access using the Jet engine.

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com



Reply With Quote
  #5  
Old   
Hugo Kornelis
 
Posts: n/a

Default Re: How to Gnerate a Random ID Number - 06-09-2007 , 03:45 PM



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

Quote:
chico_yallin (AT) yahoo (DOT) com (chico_yallin (AT) yahoo (DOT) 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() ?

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


Reply With Quote
  #6  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: How to Gnerate a Random ID Number - 06-09-2007 , 04:19 PM



Hugo Kornelis (hugo (AT) perFact (DOT) REMOVETHIS.info.INVALID) writes:
Quote:
On Sat, 9 Jun 2007 19:19:45 +0000 (UTC), Erland Sommarskog wrote:

chico_yallin (AT) yahoo (DOT) com (chico_yallin (AT) yahoo (DOT) 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

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.



--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #7  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: How to Gnerate a Random ID Number - 06-10-2007 , 02:42 AM



Bob Quintal (rquintal (AT) sPAmpatico (DOT) ca) writes:
Quote:
Erland Sommarskog <esquel (AT) sommarskog (DOT) se> wrote in
news:Xns994AD933293B9Yazorman (AT) 127 (DOT) 0.0.1:
chico_yallin (AT) yahoo (DOT) com (chico_yallin (AT) yahoo (DOT) com) writes:
I just wana make a random id number based on4 digits-for
examples??

checksum(newid()) is better than the rand() function.

Please provide instructions on the use of these functions in MS-
Access using the Jet engine.
Sorry, I did not notice that the thread was cross-posted between the
SQL Server and Access newsgroups. I assumed that since you posted in a
newsgroup for SQL Server, you wanted a solution for SQL Server. I have
no idea what might work in Access.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #8  
Old   
Bob Quintal
 
Posts: n/a

Default Re: How to Gnerate a Random ID Number - 06-10-2007 , 06:12 AM



Erland Sommarskog <esquel (AT) sommarskog (DOT) se> wrote in
news:Xns994B62FEC60E1Yazorman (AT) 127 (DOT) 0.0.1:

Quote:
Bob Quintal (rquintal (AT) sPAmpatico (DOT) ca) writes:
Erland Sommarskog <esquel (AT) sommarskog (DOT) se> wrote in
news:Xns994AD933293B9Yazorman (AT) 127 (DOT) 0.0.1:
chico_yallin (AT) yahoo (DOT) com (chico_yallin (AT) yahoo (DOT) com) writes:
I just wana make a random id number based on4 digits-for
examples??

checksum(newid()) is better than the rand() function.

Please provide instructions on the use of these functions in
MS- Access using the Jet engine.

Sorry, I did not notice that the thread was cross-posted
between the SQL Server and Access newsgroups. I assumed that
since you posted in a newsgroup for SQL Server, you wanted a
solution for SQL Server. I have no idea what might work in
Access.

I didn't notice the cross-post either, and I don't know wether
your solutin would be acceptable to the original poster. I sure
would like the functionality of newid() in Access.


--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com



Reply With Quote
  #9  
Old   
--CELKO--
 
Posts: n/a

Default Re: How to Gnerate a Random ID Number - 06-10-2007 , 10:39 AM



Quote:
I just want to make a random id number based on 4 digits
Since it for an identifier this implies that there are no duplicates
("sampling without replacement" if you want to look it up). And there
are only values 0000 thru 9999 available to you. Just generate a
table of 10,000 rows and pull one out as you need it. m




Reply With Quote
  #10  
Old   
Gert-Jan Strik
 
Posts: n/a

Default Re: How to Gnerate a Random ID Number - 06-10-2007 , 11:42 AM



[snip]
Quote:
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.

For more details, check out
http://groups.google.nl/group/micros...1ff6c9523c19f0
(url may wrap)

Gert-Jan


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.