完成阅读:推荐、原创、资讯、攻略界面UI

This commit is contained in:
huangzhuanghua
2016-06-07 18:23:29 +08:00
parent 45dd133536
commit dbd82cdf65
32 changed files with 1965 additions and 169 deletions

View File

@ -0,0 +1,44 @@
package com.gh.common.util;
import java.util.Random;
/**
* Created by LGT on 2016/6/7.
*/
public class RandomUtils {
/*
* 从 size 范围内随机 count 个不重复的数字
*/
public static int[] getRandomArray(int count, int size) {
int[] index = new int[count];
Random random = new Random(System.currentTimeMillis());
for (int i = 0; i < index.length; i++) {
if (i == 0) {
index[i] = random.nextInt(size);
} else {
random(random, index, i, size);
}
}
return index;
}
private static int random(Random random, int[] index, int i, int size) {
int seed = random.nextInt(size);
for (int j = 0; j < i; j++) {
if (index[j] == seed) {
return random(random, index, i, size);
}
}
return seed;
}
/*
* 从 size 范围内随机一个数字
*/
public static int nextInt(int size) {
Random random = new Random(System.currentTimeMillis());
return random.nextInt(size);
}
}