wangting
2024-09-27 a3e87f78ee262ca9bb7d9b0c997639d5f3295890
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.vci.client.fm.util;
 
import java.util.Set;
import java.util.TreeSet;
/***
 * 随机算法工具类
 * @author liwei
 *
 */
public class RandomUtil {
    /**
     * 在指定范围内随机选取n个随机数
     * @author liwei
     * @param num
     * @param n
     * @return
     */
    public static Set<Integer> getRandom(int num, int n) {
        Set<Integer> hs = new TreeSet<Integer>();
        while (true) {
            hs.add((int) (Math.random() * (num) + 1));
            if (hs.size() >= n) {
                break;
            }
        }
        return hs;
    }
}