简体   繁体   English

C#中的真错误测验

[英]true false quiz in c#

I'm building a auto guiz generator in C# in which take the pdf file from user and generate MCQS Fill in the blanks and true false. 我正在C#中构建一个自动guiz生成器,其中从用户那里获取pdf文件并生成MCQS。 I completed the two modules MCQS and Fill in the blanks but have the problem in generating true-false values in a random way. 我完成了两个模块MCQS和空白,但存在以随机方式生成真假值的问题。

So my problem is: how can i randomly generate true and false values? 所以我的问题是:我怎样才能随机生成真值和假值?

public bool GetRandomBoolean(Random rnd)
{
    return rnd.Next(0, 2) == 0;
}

http://msdn.microsoft.com/en-us/library/system.random.next http://msdn.microsoft.com/en-us/library/system.random.next

Edit : Note that you should not use this method in this way: 编辑 :请注意,您不应以这种方式使用此方法:

for(int i = 0; i < 1000; i++)
{
    bool randomBool = GetRandomBoolean(new Random());
}

That would generate always the same "random" boolean since it's seeded with the same time. 这将产生始终相同的“随机”布尔值,因为它是在同一时间播种的。 Instead you should reuse the random instance, fe in this way: 相反,您应该以这种方式重用随机实例fe:

var rnd = new Random();
for(int i = 0; i < 1000; i++)
{
    bool randomBool = GetRandomBoolean(rnd);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM