BUG: sparse: smarter random index selection

Fixes gh-3648.