Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

fix: Always get the same value where you want to get it at random. #163

Merged
merged 2 commits into from
Aug 13, 2022

Conversation

soranoba
Copy link
Contributor

@soranoba soranoba commented Jul 28, 2022

phone.go:70:47: SA4030: (*math/rand.Rand).Intn(n) generates a random value 0 <= x < n; that is, the generated values don't include n; rand.Intn(1) therefore always returns 0 (staticcheck)
	return fmt.Sprintf("(%s) %s", boxDigitsStart[rand.Intn(1)], out)
	                                             ^
phone.go:94:45: SA4030: (*math/rand.Rand).Intn(n) generates a random value 0 <= x < n; that is, the generated values don't include n; rand.Intn(1) therefore always returns 0 (staticcheck)
	return fmt.Sprintf("+%s%s", boxDigitsStart[rand.Intn(1)], strings.Join(slice.IntToString(ints), ""))
	                                           ^

@bxcodec
Copy link
Owner

bxcodec commented Aug 11, 2022

Hi @soranoba

Can you re-fixing this again, I just fixing some linter issue in #167

@soranoba soranoba changed the title Fix CI lint fix: Always get the same value where you want to get it at random. Aug 12, 2022
@@ -67,7 +67,7 @@ func (p Phone) tollfreephonenumber() string {
}
out += v
}
return fmt.Sprintf("(%s) %s", boxDigitsStart[rand.Intn(1)], out)
return fmt.Sprintf("(%s) %s", boxDigitsStart[rand.Intn(len(boxDigitsStart))], out)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rand.Intn(1) always returns 0.
So, boxDigitsStart[rand.Intn(1)] always is "777".

This fix is to correctly return random values.

@soranoba
Copy link
Contributor Author

@bxcodec Thank you. I did it.

Copy link
Owner

@bxcodec bxcodec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bxcodec bxcodec merged commit 9f1fc48 into bxcodec:master Aug 13, 2022
@bxcodec
Copy link
Owner

bxcodec commented Aug 13, 2022

Thanks @soranoba merged

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants