title: How to randomly select multiple rows satisfying certain conditions from a MySQL table?
body: <p>I'm looking for an efficient way of randomly selecting 100 rows satisfying certain conditions from a MySQL table with potentially millions of rows. </p>
  
  <p>Almost everything I've found suggests avoiding the use of ORDER BY RAND(), because of poor performance and scalability. </p>
  
  <p>However, <a href="http://www.paperplanes.de/2008/4/24/mysql_nonos_order_by_rand.html">this article</a> suggests ORDER BY RAND() may still be used as a "nice and fast way" to fetch randow data.</p>
  
  <p>Based on this article, below is some example code showing what I'm trying to accomplish. My questions are: </p>
  
  <ol>
  <li><p>Is this an efficient way of randomly selecting 100 (or up to several hundred) rows from a table with potentially millions of rows? </p></li>
  <li><p>When will performance become an issue?</p></li>
  </ol>
  
  <pre>
      SELECT  user.* 
      FROM    (
              SELECT  id 
              FROM    user 
              WHERE   is_active = 1
              AND     deleted = 0
              AND     expiretime > '.time().'
              AND     id NOT IN (10, 13, 15)
              AND     id NOT IN (20, 30, 50)
              AND     id NOT IN (103, 140, 250)
          ORDER BY    RAND() 
              LIMIT   100
              ) 
              AS      random_users
      STRAIGHT JOIN   user
      ON      user.id = random_users.id
  </pre>