Open ST-DDT opened 3 weeks ago
Thank you for your feature proposal.
We marked it as "waiting for user interest" for now to gather some feedback from our community:
If you would like to see this feature be implemented, please react to the description with an up-vote (:+1:).
If you have a suggestion or want to point out some special cases that need to be considered, please leave a comment, so we are aware about them.
We would also like to hear about other community members' use cases for the feature to give us a better understanding of their potential implicit or explicit requirements.
We will start the implementation based on:
the number of votes (:+1:) and comments
the relevance for the ecosystem
availability of alternatives and workarounds
and the complexity of the requested feature
We do this because:
There are plenty of languages/countries out there and we would like to ensure that every method can cover all or almost all of them.
Every feature we add to faker has "costs" associated to it:
Clear and concise description of the problem
The current arrayElements method only takes elements from an array once. The multiple method only uses a function as input.
I need a method to pick random elements from an array multiple times.
Suggested solution
Either as an additional parameter for the existing arrayElements
repeatedElements: boolean = false
or a new method (not sure what to call it)Here a pseudo implementations with some potential performance improvements (safes a few invocations to faker.number.int by stacking them):
The performance part needs actual benchmarks though.
Alternative
Keep using the existing code.
Additional context
This method can be used to improve the performance of the string module and similar modules.
And also reduce code duplication a bit, namely code like this:
https://github.com/faker-js/faker/blob/af1dbcdbf363a12c448834dff031a698c8925e2e/src/modules/string/index.ts#L148-L151
Due to "improvements" you would need to call faker.number.int() only once per 11 random elements of 26 characters.