MCPcopy Create free account
hub / github.com/Pallinder/go-randomdata / BoundedDigits

Function BoundedDigits

postalcodes.go:233–246  ·  view source on GitHub ↗

BoundedDigits generates a string of N random digits, padded with zeros if necessary. The output is restricted to the given range.

(digits, low, high int)

Source from the content-addressed store, hash-verified

231// BoundedDigits generates a string of N random digits, padded with zeros if necessary.
232// The output is restricted to the given range.
233func BoundedDigits(digits, low, high int) string {
234 if low > high {
235 low, high = high, low
236 }
237
238 max := int(math.Pow10(digits)) - 1
239 if high > max {
240 high = max
241 }
242
243 num := privateRand.Intn(high-low+1) + low
244 format := fmt.Sprintf("%%0%dd", digits)
245 return fmt.Sprintf(format, num)
246}

Callers 1

PostalCodeFunction · 0.85

Calls 1

IntnMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…