指定概率根据随机数执行操作 和苹果机游戏差不多的
public class demo { private string _name; public string Name { get { return _name; } set { _name = value; } } private int _rate; public int Rate { get { return _rate; } set { _rate = value; } } public demo(string name, int rate) { _name = name; _rate = rate; } } class Program { static void Main(string[] args) { Random rd = new Random(); demo[] arraylist = new demo[3] { new demo("苹果", 20), new demo("橘子", 80), new demo("香蕉", 10) }; for (var i = 0; i < arraylist.Length; i++) { if (rd.Next(0, 101) <= arraylist[i].Rate) { //执行 } else { i++; } } } }