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)
| 231 | // BoundedDigits generates a string of N random digits, padded with zeros if necessary. |
| 232 | // The output is restricted to the given range. |
| 233 | func 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 | } |
no test coverage detected
searching dependent graphs…