My rand function seems like a better solution than yours ( it's also shorter )