Menu

#53 random algorithm sucks

open-fixed
nobody
None
5
2005-03-25
2003-09-23
No

somehow you don't always get 10 random songs on index.php

Discussion

  • Philip Lowman

    Philip Lowman - 2004-02-02
    • summary: random algorithm broken --> random algorithm sucks
     
  • David Ward

    David Ward - 2005-01-02

    Logged In: YES
    user_id=272259

    The way that the songs are shown is in two stages. The
    first gets a list of 10 songs, the second shows them if they
    are (possibly) not hidden.

    Replacing random_song_ids() with the following will make
    sure that only "active" song ids are fetched in the first place.

    function random_song_ids($number) {
    $random_song_ids = array();

    $query = "select song_id from songs where
    {$GLOBALS['show_active']} order by rand() limit $number";
    $result = tunez_query($query);

    while ($row = mysql_fetch_object($result)) {
    $random_song_ids[] = $row->song_id;
    }

    return $random_song_ids;
    }

     
  • David Ward

    David Ward - 2005-01-02

    Logged In: YES
    user_id=272259

    I've uploaded a patch (#1094606) with this fix.

     
  • Philip Lowman

    Philip Lowman - 2005-03-25
    • status: open --> open-fixed
     

Log in to post a comment.