I need to generate random numbers starting from 1 to 100 with a repetition factor of 7 in java. ie, each number should repeat exactly for 7 times. So, i need to generate 700 numbers in total.
Could anyone please help me how to proceed?
Thanks in advance...
Check this
ArrayList list1 = new ArrayList();
Random rnd = new Random();
for (int i = 0; i < 7; i++) {
ArrayList list2 = new ArrayList();
while(list2.size() != 100) {
int num = rnd.nextInt(101);
if( num == 0 || list2.contains(num)) {
continue;
}
list2.add(num);
}
list1.addAll(list2);
}
System.out.println(list1.size());
list2 contains subeset of random numbers between 1 to 100 and list1 contains 7 times list2.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.