作者sanya423 (我想要ALL PASS...)
看板C_Sharp
标题[问题] random语法怎麽用??
时间Wed Mar 29 22:27:11 2006
用random写出骰子程式...
实现一个能设定骰子点数出现机率的点数产生器
Ex. 执行产生50次点数
设定一点出现次数 10次 、 二点 10次、 三点 10次
四点 10次、五点 5次、六点 5次
产生的结果为乱数产生 1~6 点数并依照设定值产生各点数
次数
以下是部分程式....
class Mydice
{
//初始化阵列预设值为0
public static void init_arary(ref int[] target)
{
int i = 0;
while (i < target.Length)
{
target[i] = 0;
i++;
}
}
//显示阵列中所有值
public static void show(int[] data)
{
int i = 0;
while (i < data.Length)
{
Console.Write("{0,-4}", data[i]);
i++;
}
}
//测试点数阵列是否已超过设定出现的次数
//参数 : int[] test 纪录出现点数阵列 , int[] data 点数存放阵列 , int index 当次产生的点数(测试值)
//传回值 : 传回bool值
public static bool test_val(int[] test , int[] data ,int index)
{
bool cond = false;
if (test[index - 1] >= data[index - 1])
{
cond = true;
}
return cond;
}
//产生随机点数
//参数 : int[] numbers 设定各点数出现比率值, int total 点数产生次数
//传回值 : 传回整数阵列值 传回点数出现统计阵列
public static int[] disc_generator(int[] numbers, int total)
{
//这边不知道该怎麽写......
}
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 203.68.164.14