BUG: sparse: smarter random index selection

Fixes gh-3648.
Merge pull request #3650 from perimosocordiae/patch-5

BUG: sparse: smarter random index selection