我正在尝试从 java 中具有所需概率的数组字符串列表生成随机字符串。我能够生成随机字符串但不知道如何处理概率。我必须运行程序几乎 25-30 次
Probability for abc is 10%
for def is 60%
for ghi is 20%
for danny is 10%
但我无法做到这一点。
import java.util.*;
public class newyork
{
public static void main(String[]args) throws Exception
{
// othr fun
public static void abc()
{
//Strings to display
String [] random = {"abc","def", "ghi","danny"};
//Pick one by one
String no1= random[(int) (Math.random()*(random.length))];
String no2 = random[(int) (Math.random()*(random.length))];
String no3 = random[(int) (Math.random()*(random.length))];
//print randomly generated strings
System.out.println("Here you go : " + no1 + " " + no2 + " " + no3 + ");
}