0
点赞
收藏
分享

微信扫一扫

java 按概率产生

芷兮离离 2022-06-30 阅读 67

 

import java.util.Random;

import org.junit.Test;

public class Demo1 {
public void getChance(int percentage){
Random random = new Random();
int i = random.nextInt(99);
if(i>=0&&i<percentage)
System.out.println("true");
else
System.out.println("false");
}
@Test
public void test(){
for(int i=0;i<100;i++){
this.getChance(76); //76%概率
}
}

  

举报

相关推荐

0 条评论