java 按概率产生

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%概率
		}
	}

  

原文地址:https://www.cnblogs.com/wdw31210/p/9443401.html