datafaker
datafaker copied to clipboard
Add weighted selection
Support weighted faking in custom providers.
Inspired from https://fakerjs.dev/api/helpers#weightedarrayelement
faker.helpers.weightedArrayElement([
{ weight: 5, value: 'sunny' },
{ weight: 4, value: 'rainy' },
{ weight: 1, value: 'snowy' }
]) // 'sunny', 50% of the time, 'rainy' 40% of the time, 'snowy' 10% of the time
With custom providers, we could make a YML provider with weights associated to each value
en:
faker:
insectsfromfile:
ants: [5, 'Driver ant', 4, 'Fire ant', 1, 'Harvester ant']
Questions
- Is there a way to achieve weighted faking with current codebase ?