parameters: (sid)
docstring: Fetch a random song, abiding by all election block, request block, and
  	availability rules.  Falls back to get_random_ignore_requests on failure.
docstring_summary: Fetch a random song, abiding by all election block, request block, and
  	availability rules.  Falls back to get_random_ignore_requests on failure.
docstring_tokens: Fetch a random song abiding by all election block request block and availability rules . Falls back to get_random_ignore_requests on failure .
function: def get_random_song(sid):
      """
  	Fetch a random song, abiding by all election block, request block, and
  	availability rules.  Falls back to get_random_ignore_requests on failure.
  	"""
  
      sql_query = (
          "FROM r4_song_sid "
          "JOIN r4_songs USING (song_id) "
          "JOIN r4_album_sid ON (r4_album_sid.album_id = r4_songs.album_id AND r4_album_sid.sid = r4_song_sid.sid) "
          "WHERE r4_song_sid.sid = %s "
          "AND song_exists = TRUE "
          "AND song_cool = FALSE "
          "AND song_request_only = FALSE "
          "AND song_elec_blocked = FALSE "
          "AND album_requests_pending IS NULL"
      )
      num_available = db.c.fetch_var("SELECT COUNT(song_id) " + sql_query, (sid,))
      log.info(
          "song_select", "Song pool size (cooldown, blocks, requests): %s" % num_available
      )
      offset = 0
      if num_available == 0:
          log.warn("song_select", "No songs available despite no timing rules.")
          log.debug(
              "song_select",
              "Song select query: SELECT COUNT(song_id) " + (sql_query % (sid,)),
          )
          return get_random_song_ignore_requests(sid)
      else:
          offset = random.randint(1, num_available) - 1
          song_id = db.c.fetch_var(
              "SELECT song_id " + sql_query + " LIMIT 1 OFFSET %s", (sid, offset)
          )
          return Song.load_from_id(song_id, sid)
function_tokens: def get_random_song ( sid ) : sql_query = ( "FROM r4_song_sid " "JOIN r4_songs USING (song_id) " "JOIN r4_album_sid ON (r4_album_sid.album_id = r4_songs.album_id AND r4_album_sid.sid = r4_song_sid.sid) " "WHERE r4_song_sid.sid = %s " "AND song_exists = TRUE " "AND song_cool = FALSE " "AND song_request_only = FALSE " "AND song_elec_blocked = FALSE " "AND album_requests_pending IS NULL" ) num_available = db . c . fetch_var ( "SELECT COUNT(song_id) " + sql_query , ( sid , ) ) log . info ( "song_select" , "Song pool size (cooldown, blocks, requests): %s" % num_available ) offset = 0 if num_available == 0 : log . warn ( "song_select" , "No songs available despite no timing rules." ) log . debug ( "song_select" , "Song select query: SELECT COUNT(song_id) " + ( sql_query % ( sid , ) ) , ) return get_random_song_ignore_requests ( sid ) else : offset = random . randint ( 1 , num_available ) - 1 song_id = db . c . fetch_var ( "SELECT song_id " + sql_query + " LIMIT 1 OFFSET %s" , ( sid , offset ) ) return Song . load_from_id ( song_id , sid )