Select random row from MySQL (with probability)
        Posted  
        
            by James Simpson
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by James Simpson
        
        
        
        Published on 2010-04-26T19:14:56Z
        Indexed on 
            2010/04/26
            19:23 UTC
        
        
        Read the original article
        Hit count: 427
        
I have a MySQL table that has a row called cur_odds which is a percent number with the percent probability that that row will get selected. How do I make a query that will actually select the rows in approximately that frequency when you run through 100 queries for example?
I tried the following, but a row that has a probability of 0.35 ends up getting selected around 60-70% of the time.
SELECT * FROM table ORDER BY RAND()*cur_odds DESC
© Stack Overflow or respective owner