有以下需求:
  1、以p的概率产生0,以1-p的概率产生1
  2、有具体的算法实现分不够的话可以另开贴

解决方案 »

  1.   


        Random rand = new Random();
            static void Main(string[] args)
            {
                Random rand = new Random();
                double dou = 0.8888;
                Thread thread = new Thread(new ThreadStart(() =>
                    {
                        int pCount = 0;
                        int i = 0;
                        while (i < 1000)
                        {
                            i++;
                            if (rand.NextDouble() < dou)
                            {
                                pCount++;
                                Console.WriteLine(i + ":  p");
                            }
                            else
                            {
                                Console.WriteLine(i + ":  1-p");
                            }
                        }
                        Console.WriteLine("p  " + pCount + " times.");
                        Console.WriteLine("1-p " + (1000 - pCount) + " times");
                        Console.WriteLine("set 88.88%,actual " + (pCount / 10.000000) + "%");
                    }));
                thread.Start();
                Console.Read();
            }
      

  2.   

    用Random产生一个0~1的随机数,小于0.0987就是中奖。