Add method/option to pick elements from an array multiple times #3222
Labels
c: feature
Request for new feature
m: helpers
Something is referring to the helpers module
p: 1-normal
Nothing urgent
s: waiting for user interest
Waiting for more users interested in this feature
Milestone
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:
faker/src/modules/string/index.ts
Lines 148 to 151 in af1dbcd
Due to "improvements" you would need to call faker.number.int() only once per 11 random elements of 26 characters.
The text was updated successfully, but these errors were encountered: