关于一定概率随机函数的算法及实现 有以下需求: 1、以p的概率产生0,以1-p的概率产生1 2、有具体的算法实现分不够的话可以另开贴 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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(); } 用Random产生一个0~1的随机数,小于0.0987就是中奖。 对GridView实现编辑删除时如何获取所要编辑或删除的行的索引? 什么是 值按位组合 请教一个关于录入的问题 小妹求教,如何实现本地文件移动到某地的问题! 关于Control的一个问题 将DBF导入SQLserver用C#怎么写?急,在线等,谢谢各位! 在C#中如何实现分屏 dsoframer office工具栏失效问题 listview 问题求教!!! 急用,请知道者速回答案,谢谢!!!!!!!!!! 求解 关于皮肤的 c# 怎么关闭一个程序的互拆体句柄。
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();
}