-
-
Notifications
You must be signed in to change notification settings - Fork 953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(number): add distributor functions #3375
base: next
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for fakerjs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## next #3375 +/- ##
==========================================
- Coverage 99.97% 99.97% -0.01%
==========================================
Files 2811 2814 +3
Lines 217414 217443 +29
Branches 949 959 +10
==========================================
+ Hits 217359 217387 +28
- Misses 55 56 +1
🚀 New features to boost your workflow:
|
I'm also not sure whether |
I don't like calling it "exponentialDistribution " because you're not returning a distribution, you are returning a single value from that distribution. So I'd call it exponentialValue or floatExponential or something similar to emphasise the thing that is returned is a float or a value. |
I'm not even sure that is the case.
Good idea. I'm not finally sure which term I would like to use but stepping away from calling it I'm currently considering one of these:
|
Team decision The feature will be implemented by extending the already existing methods ( We are currently unsure how to name the parameter. While distribution is okay, we are not sure if this is the mathmatical correct term. |
Ready for review. I changed the implementations to use a |
export function uniformDistributor(): Distributor { | ||
return UNIFORM_DISTRIBUTOR; | ||
} | ||
|
||
const UNIFORM_DISTRIBUTOR: Distributor = ({ next }) => next(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought quite long about it. What exactly was your reasoning to extract the uniform function implementation into it's own function expression? The only benifit I was able to see, would be function reference comparison:
const a = uniformDistributor();
const b = uniformDistributor();
a === b // true
Was that your reasoning? If yes, is this really desired? 🤔
Implements #1862
Adds a
distributor
option to faker.number.int and float. The distributor function can be used to influence the distribution of the generated values. E.g. uniformDistributor and exponentialDistributor.The following table shows the rough distribution of values generated using
exponentialDistributor({ base: x })
:The exponential distribution is achieved by using
base ** exponent
where exponent is a random float between 0 and 1.The result is then stretched evenly to fit to
min
andmax
.