diff --git a/src/main/java/org/hisp/dhis/utils/DataRandomizer.java b/src/main/java/org/hisp/dhis/utils/DataRandomizer.java index ab5a0aa..7911244 100644 --- a/src/main/java/org/hisp/dhis/utils/DataRandomizer.java +++ b/src/main/java/org/hisp/dhis/utils/DataRandomizer.java @@ -3,11 +3,7 @@ import java.time.LocalDate; import java.time.ZoneId; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Random; +import java.util.*; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -149,6 +145,16 @@ public static T randomElementFromList( List list ) Random rand = new Random(); return list.get( rand.nextInt( list.size() ) ); } + + public static List randomElementsFromList( List list, int elements ) + { + Collections.shuffle( list ); + if ( elements > list.size() ) + { + elements = list.size(); + } + return list.subList( 0, elements ); + } /** * Generates random boolean value