Skip to content

Commit 0266145

Browse files
authored
Merge pull request #34 from jiro4989/hotfix/number-digit
🐛 Fix random number digit
2 parents 018070e + 68ce2d0 commit 0266145

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/faker/provider/util.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import macros, random
22
from strformat import `&`
33
from strutils import join, align
4+
from math import `^`
45

56
macro genProc*(names, modules: untyped): untyped =
67
## プロシージャ定義を生成する。 `names` がプロシージャ名、 `modules` はプロシ
@@ -42,7 +43,8 @@ macro genProc*(names, modules: untyped): untyped =
4243

4344
proc formatNumbers*(r: var Rand, format: string): string =
4445
proc alignFmt(r: var Rand, buf: string): string =
45-
let num = $r.rand(1..buf.len)
46+
let max = 10 ^ buf.len - 1
47+
let num = $r.rand(1..max)
4648
result = num.align(buf.len, '0')
4749

4850
var buf: string

0 commit comments

Comments
 (0)