dmgk/faker

Fake Number returns String

Closed this issue · 5 comments

Why does your fake number generator return a string?
I would imaging that most cases were someone would want a fake number they want a number and not a string, and if they needed a string it is easy enough to convert it.

dmgk commented

Everything (except Date) in Faker returns strings. The standard library already provides ways to generate fake (random) numbers with math/rand and crypto/rand.

Second on this. I want to have a consistent way of generating fake data. Using this lib for some data, and crypto.Rand for other data types just leads to inconsistent data generation within our test suites.

I agree with @djarbz, returning a number type makes a lot more sense when you're generating a number. The argument that the standard library already provides way to generated fake numbers is non-sensical IMO. If you want any rand number sure the math/rand will work but as soon as you want more control like a number between this range, or a positive number, or a negative number etc you're having to write little utility functions one would hope their fake data lib would do for them.

dmgk commented

Number interface now has three new methods that return positive integers:

NumberInt(digits int) int     // => 213
NumberInt32(digits int) int32 // => 92938
NumberInt64(digits int) int64 // => 1689541633257139096

That should reduce the need for conversion helper functions. faker.Number().Number() still returns string to preserve backward compatibility.

Excellent, thank you!