java-faker
java-faker copied to clipboard
Idea: Random subset
Is your feature request related to a problem? Please describe.
Currently it's hard to get a Set, which is a random subset of a collection.
kotlin example of use case
val options = setOf(
"cheese",
"olives",
"onion",
"pepperoni",
"peppers",
)
val selectedIngredients =
options
.shuffled()
.take(ThreadLocalRandom.current().nextInt(options.size))
.toSet()
java example
List<String> options = Arrays.asList(
"cheese",
"olives",
"onion",
"pepperoni",
"peppers");
Collections.shuffle(options, ThreadLocalRandom.current());
options
.stream()
.limit(ThreadLocalRandom.current().nextInt(options.size()))
.collect(Collectors.toSet());
Describe the solution you'd like
faker.options.randomSubset("cheese", "olives", "bacon", "ham")
Describe alternatives you've considered see the alternative code samples above
Additional context Add any other context or screenshots about the feature request here.
Hi, we will volunteer to work on this issue in October/November. For the project maintainer, please let us know if this is okay and if you want it fixed.
Hey @komminen.
Sure, I'm happy to contribute code.
I wasn't sure if you wanted the change to your API or not.
I think the project is dead somehow?
@wcarmon, @komminen , @joaquinjsb
may be a bit too late but anyway there is a port of java-faker to jdk8 with lots of improvements including subsets generation https://github.com/datafaker-net/datafaker/pull/129