programming question

@aparrish@friend.camp

Content warning: programming question

so i have an array with several thousand elements, ~50% of which are empty. the empty elements aren't uniformly distributed over the length of the array. (it's a hash table.) i want to select a non-empty array element at random. is there a clever way to do this that (a) is constant time (or close); (b) doesn't require a second data structure; and (c) isn't just sampling at random in a loop until you get a hit? (this is for an embedded application so RAM is at a premium)