<?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: Solutions to the ORDER BY RAND() problem.</title>
	<atom:link href="http://www.koopman.me/2009/01/solutions-to-the-order-by-rand-problem/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.koopman.me/2009/01/solutions-to-the-order-by-rand-problem/</link>
	<description>Dave Koopman&#039;s Blog</description>
	<lastBuildDate>Wed, 08 Feb 2012 22:35:41 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: DaveK</title>
		<link>http://www.koopman.me/2009/01/solutions-to-the-order-by-rand-problem/comment-page-1/#comment-43</link>
		<dc:creator>DaveK</dc:creator>
		<pubDate>Sun, 19 Apr 2009 05:52:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.koopman.me/?p=1361#comment-43</guid>
		<description>Only works when you want one result.  Back to the drawing board if you want more than one.  Might be better to run in a loop, pseudo code:

$max = SELECT MAX(`id`) FROM `tbl`)
$results = array()
$numToGet = 100
while (count($results) &lt; $numToGet)

  SELECT *
  FROM `tbl` AS `l1`
  JOIN
  (SELECT (RAND() * $max) AS `id`) AS `l2`
  WHERE
  `l1`.`id` &gt;= `l2`.`id`
  AND l1.id NOT IN ($results)
  ORDER BY
  `l1`.`id` ASC
  LIMIT 1
  INTO $results[]

end while</description>
		<content:encoded><![CDATA[<p>Only works when you want one result.  Back to the drawing board if you want more than one.  Might be better to run in a loop, pseudo code:</p>
<p>$max = SELECT MAX(`id`) FROM `tbl`)<br />
$results = array()<br />
$numToGet = 100<br />
while (count($results) < $numToGet)</p>
<p>  SELECT *<br />
  FROM `tbl` AS `l1`<br />
  JOIN<br />
  (SELECT (RAND() * $max) AS `id`) AS `l2`<br />
  WHERE<br />
  `l1`.`id` >= `l2`.`id`<br />
  AND l1.id NOT IN ($results)<br />
  ORDER BY<br />
  `l1`.`id` ASC<br />
  LIMIT 1<br />
  INTO $results[]</p>
<p>end while</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://www.koopman.me/2009/01/solutions-to-the-order-by-rand-problem/comment-page-1/#comment-35</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Fri, 09 Jan 2009 17:24:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.koopman.me/?p=1361#comment-35</guid>
		<description>Wow! What a great solution to the order by rand problem! I always wondered how to get around order by rand issues, the performance of order by rand is just horrible! This is a fast and speedy work around!</description>
		<content:encoded><![CDATA[<p>Wow! What a great solution to the order by rand problem! I always wondered how to get around order by rand issues, the performance of order by rand is just horrible! This is a fast and speedy work around!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

