speeding up random query