所以这是基本代码:
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
protected Random random;
public Form1()
{
InitializeComponent();
random = new Random();
}
private void Form1_Load(object sender, EventArgs e)
{ }
private void button1_Click(object sender, EventArgs e)
{
bool button1Clicked = true;
if (button1Clicked == true) { ITIpanel.Visible = true; }
}
private void ITIpanel_Paint(object sender, PaintEventArgs e)
{
ITItimer.Enabled = true;
}
private void ITItimer_Tick(object sender, EventArgs e)
{
double rand = random.NextDouble();
if (rand < .50d) { bluestimPanel.Visible = true; }
else if (rand > .5d) { redstimPanel.Visible = true; }
ITItimer.Enabled = false;
}
private void bluestimPanel_Paint(object sender, PaintEventArgs e)
{
Trialtimer.Enabled = true;
}
private void redstimPanel_Paint(object sender, PaintEventArgs e)
{
Trialtimer.Enabled = true;
}
private void Trialtimer_Tick(object sender, EventArgs e)
{
bluestimPanel.Visible = false;
redstimPanel.Visible = false;
Trialtimer.Enabled = false;
ITIpanel.Visible = true;
}
}
}
正如您所看到的,该计划本身相当直接。在ITItimer的刻度线处,红色或蓝色面板随机出现。我想修改它,如果ITItimer共计10次,红色和蓝色面板都会发生5次。
我已经研究了一个星期左右,还没有找到解决方案。关于如何才能最好地实现这一目标的任何想法?
我实际上有以下工作:
double rand = random.NextDouble();
if (rand < .50d && blue < 5) { bluestimPanel.Visible = true; }
else if (blue == 5) { redstimPanel.Visible = true; }
if (rand > .5d && red < 5) { redstimPanel.Visible = true; }
else if (red == 5) { bluestimPanel.Visible = true; }
if (red >= 5 && blue >= 5) { panel1.Visible = true; }
这不是世界上最漂亮的东西。但它完成了工作。
答案 0 :(得分:2)
使用大多数普通库例程的随机数是伪随机性的低质量来源。如果这是一项随机科学研究,这将是您的协议设计中的一个缺陷。
我建议的方法是考虑这种随机安排至少N次试验的方法,其中有X种试验类型。
以下是用于说明概念的伪代码。
Let MinimumTrials be N MOD X + X
Let SessionList be a List<Trial>
For Each TrialType
add X instances of that trial type to SessionList
Shuffle(SessionList)
然后,您的会话引擎可以在遍历SessionList时调用各个试验,以均匀分发可能的试用订单。请注意,Shuffle是一种需要一定程度的技巧才能正确的操作,在SO上搜索是一个很好的起点。