Fix sprand for very small matrices

To fix #6070.

cc: @jiahao, @timholy