Skip to content

Add method like fake.sample() that returns specified number N elements from array #80

@serhalp

Description

@serhalp

fake.sample() takes an array and returns a random element from that array. Occasionally, we have a need to generate an array of N elements out of an array of M elements. Sometimes we have a uniqueness requirement and sometimes we do not.

What could we call this? I'm a bit uninspired when it comes to naming this.

Chance.js calls these pickone and pickset, which aren't awful, but we already call our pickone sample. sampleMany? multiSample? fake.subset() is not bad perhaps, at least for the case of unique elements.

Would we want separate methods for the unique vs. nonunique case or a flag or just support one or the other?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions