Make randomIndex generation more flexible.