1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public static void main(String[] args) { Map<String, Double> groups = new HashMap<>(); groups.put("g1", 15d); groups.put("g2", 25d); groups.put("g3", 30d); groups.put("g4", 30d); Map<String, Integer> groupCountMap = new HashMap<>(); long total = 100000; for (long i = 0; i < total; i++) { String group_super_id = choose(UUID.randomUUID().toString(), groups); if (!groupCountMap.containsKey(group_super_id)) { groupCountMap.put(group_super_id, 1); } groupCountMap.put(group_super_id, groupCountMap.get(group_super_id) + 1); } for (Map.Entry<String, Integer> entry : groupCountMap.entrySet()) { log.info("group : {} count : {} percent :{}", entry.getKey(), entry.getValue(), new BigDecimal(entry.getValue()).divide(new BigDecimal(total), 4, RoundingMode.UP).multiply(new BigDecimal(100)) + "%"); } }
|