在做2048,这个问题不知道应该怎么用程序解决。
先多谢大家的热心解答!
double random = Math.random();
if (random>0.9) {
return 4;
}else {
return 2;
}
不知道你需要的什么的算法,但是你描述的很模糊,听不明白
生成0-8的随机数
如果随机数 小于8 让数字等于2
否则等于4
前方施工了,请忽略。打扰了。
public static void main(String[] args) {
List list=new ArrayList();
for (int i = 0; i < 9; i++) {
list.add(i);
}
Collections.shuffle(list);//打乱数据
int a=list.get(0)==0?4:2;//等于0的几率为9分之一;如果true则a=4;否则a=2
}