This is a little more complex than one may think initially. Most uniform probability random number generators generate a random value between zero and unity and then covert to a specific range. A typical php function is m_rand which allows setting a start and end value to the range. Obviously to select a Download at random one would need to find the lowest and highest id values and then use those to generate a random number.
Finding the range is not itself sufficient as one has to take into account if a category and its sub categories are selected, Further there is no guarentee that all ids in a range have appropriate permissions, view access and similar. Then of course there will be gaps in the permitted ranges. That would mean multiple attempts to see if an id exists and if it is valid. In principle therecould be a large number of invalid ids taking an unknown time.