<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Random Number Generator in T-SQL</title>
	<atom:link href="http://sqlfool.com/2009/06/random-number-generator-in-tsql/feed/" rel="self" type="application/rss+xml" />
	<link>http://sqlfool.com/2009/06/random-number-generator-in-tsql/</link>
	<description>Adventures in SQL Tuning - a blog for the rest of us</description>
	<lastBuildDate>Thu, 04 Feb 2010 08:21:02 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Mark Horninger</title>
		<link>http://sqlfool.com/2009/06/random-number-generator-in-tsql/comment-page-1/#comment-4903</link>
		<dc:creator>Mark Horninger</dc:creator>
		<pubDate>Fri, 28 Aug 2009 10:32:51 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=489#comment-4903</guid>
		<description>Thanks!  this saved me some time this AM!</description>
		<content:encoded><![CDATA[<p>Thanks!  this saved me some time this AM!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Timmy</title>
		<link>http://sqlfool.com/2009/06/random-number-generator-in-tsql/comment-page-1/#comment-4886</link>
		<dc:creator>Timmy</dc:creator>
		<pubDate>Wed, 12 Aug 2009 18:15:29 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=489#comment-4886</guid>
		<description>Excellent script! I modified it a tiny bit to accomplish something different, but the guts are all yours!</description>
		<content:encoded><![CDATA[<p>Excellent script! I modified it a tiny bit to accomplish something different, but the guts are all yours!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Weekly Link Post 97 &#171; Rhonda Tipton&#8217;s WebLog</title>
		<link>http://sqlfool.com/2009/06/random-number-generator-in-tsql/comment-page-1/#comment-4410</link>
		<dc:creator>Weekly Link Post 97 &#171; Rhonda Tipton&#8217;s WebLog</dc:creator>
		<pubDate>Mon, 08 Jun 2009 01:37:33 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=489#comment-4410</guid>
		<description>[...] Michelle Ufford has posted a Random Number Generator in T-SQL. [...]</description>
		<content:encoded><![CDATA[<p>[...] Michelle Ufford has posted a Random Number Generator in T-SQL. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: green bay packers &#187; Parapsychology</title>
		<link>http://sqlfool.com/2009/06/random-number-generator-in-tsql/comment-page-1/#comment-4389</link>
		<dc:creator>green bay packers &#187; Parapsychology</dc:creator>
		<pubDate>Sat, 06 Jun 2009 10:14:53 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=489#comment-4389</guid>
		<description>[...] Random Number Generator in T-SQL : SQL Fool [...]</description>
		<content:encoded><![CDATA[<p>[...] Random Number Generator in T-SQL : SQL Fool [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Generate a random number in SQL Server &#124; John Sansom - SQL Server DBA in the UK</title>
		<link>http://sqlfool.com/2009/06/random-number-generator-in-tsql/comment-page-1/#comment-4374</link>
		<dc:creator>Generate a random number in SQL Server &#124; John Sansom - SQL Server DBA in the UK</dc:creator>
		<pubDate>Fri, 05 Jun 2009 11:52:32 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=489#comment-4374</guid>
		<description>[...] authors, Michelle Ufford  recently posted her method for generating a random number, in the post Random Number Generator in T-SQL. This got me thinking and I decided to do a little investigation of my own to identify what is [...]</description>
		<content:encoded><![CDATA[<p>[...] authors, Michelle Ufford  recently posted her method for generating a random number, in the post Random Number Generator in T-SQL. This got me thinking and I decided to do a little investigation of my own to identify what is [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Lowe</title>
		<link>http://sqlfool.com/2009/06/random-number-generator-in-tsql/comment-page-1/#comment-4362</link>
		<dc:creator>Aaron Lowe</dc:creator>
		<pubDate>Thu, 04 Jun 2009 20:27:39 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=489#comment-4362</guid>
		<description>I use the same as Adam does:

RAND(CHECKSUM(NEWID()))

I actually got it from Itzik about 5 years ago at SQLConnections in Las Vegas.</description>
		<content:encoded><![CDATA[<p>I use the same as Adam does:</p>
<p>RAND(CHECKSUM(NEWID()))</p>
<p>I actually got it from Itzik about 5 years ago at SQLConnections in Las Vegas.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam Machanic</title>
		<link>http://sqlfool.com/2009/06/random-number-generator-in-tsql/comment-page-1/#comment-4358</link>
		<dc:creator>Adam Machanic</dc:creator>
		<pubDate>Thu, 04 Jun 2009 15:16:20 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=489#comment-4358</guid>
		<description>I don&#039;t know about faster, but I think you&#039;ll get better distribution and overall randomness with:

DECLARE @maxRandomValue TINYINT = 100
	, @minRandomValue TINYINT = 0;
 
SELECT CAST(((@maxRandomValue + 1) - @minRandomValue) 
	* RAND(CHECKSUM(NEWID())) + @minRandomValue AS TINYINT) AS &#039;randomNumber&#039;;</description>
		<content:encoded><![CDATA[<p>I don&#8217;t know about faster, but I think you&#8217;ll get better distribution and overall randomness with:</p>
<p>DECLARE @maxRandomValue TINYINT = 100<br />
	, @minRandomValue TINYINT = 0;</p>
<p>SELECT CAST(((@maxRandomValue + 1) &#8211; @minRandomValue)<br />
	* RAND(CHECKSUM(NEWID())) + @minRandomValue AS TINYINT) AS &#8216;randomNumber&#8217;;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AlexCuse</title>
		<link>http://sqlfool.com/2009/06/random-number-generator-in-tsql/comment-page-1/#comment-4356</link>
		<dc:creator>AlexCuse</dc:creator>
		<pubDate>Thu, 04 Jun 2009 14:09:16 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=489#comment-4356</guid>
		<description>This got me curious, so I did a little digging to see if there was anything a bit more production-ready and came across this (the accepted answer):

http://stackoverflow.com/questions/94906/how-do-i-return-random-numbers-as-a-column-in-sql-server-2005</description>
		<content:encoded><![CDATA[<p>This got me curious, so I did a little digging to see if there was anything a bit more production-ready and came across this (the accepted answer):</p>
<p><a href="http://stackoverflow.com/questions/94906/how-do-i-return-random-numbers-as-a-column-in-sql-server-2005" rel="nofollow">http://stackoverflow.com/questions/94906/how-do-i-return-random-numbers-as-a-column-in-sql-server-2005</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AlexCuse</title>
		<link>http://sqlfool.com/2009/06/random-number-generator-in-tsql/comment-page-1/#comment-4354</link>
		<dc:creator>AlexCuse</dc:creator>
		<pubDate>Thu, 04 Jun 2009 13:56:03 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=489#comment-4354</guid>
		<description>Not sure how it stacks up speed wise (the answer is probably NOT WELL ;) ) but one of my friends showed me this a while back:

CREATE VIEW RandomView 
AS SELECT RAND() AS Val;


GO

CREATE FUNCTION RandomFloat(@MinValue INT, @MaxValue INT)
RETURNS FLOAT AS
BEGIN
	RETURN (SELECT ((@MaxValue - @MinValue) * Val) + @MinValue FROM RandomView);
END

GO

Casting it to an int would be trivial.  What I like about this is that unlike the builtin RAND() method it will return a different value for each row in the set.  

select top 5 ROW_NUMBER() over (order by TABLE_NAME) blah
	, dbo.RandomFloat(15, 100) random_works
	, RAND() random_builtin
from INFORMATION_SCHEMA.TABLES

Kind of a stupid coding trick, but I find myself using something like this once in a while.</description>
		<content:encoded><![CDATA[<p>Not sure how it stacks up speed wise (the answer is probably NOT WELL <img src='http://sqlfool.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ) but one of my friends showed me this a while back:</p>
<p>CREATE VIEW RandomView<br />
AS SELECT RAND() AS Val;</p>
<p>GO</p>
<p>CREATE FUNCTION RandomFloat(@MinValue INT, @MaxValue INT)<br />
RETURNS FLOAT AS<br />
BEGIN<br />
	RETURN (SELECT ((@MaxValue &#8211; @MinValue) * Val) + @MinValue FROM RandomView);<br />
END</p>
<p>GO</p>
<p>Casting it to an int would be trivial.  What I like about this is that unlike the builtin RAND() method it will return a different value for each row in the set.  </p>
<p>select top 5 ROW_NUMBER() over (order by TABLE_NAME) blah<br />
	, dbo.RandomFloat(15, 100) random_works<br />
	, RAND() random_builtin<br />
from INFORMATION_SCHEMA.TABLES</p>
<p>Kind of a stupid coding trick, but I find myself using something like this once in a while.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
