using System;namespace ConsoleApplication6
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Random random=new Random();
for(int i=0;i<7;i++)
{int score=random.Next(32);
Console.WriteLine(score);}
}
}
}
这段代码是产生 32以内的7个随机数字
可是他会产生2个相同的数字的和零,我想把相同的数和零弄掉弄掉该怎么写?

解决方案 »

  1.   

    你意思就是在Console.WriteLine();之前去把那个随机数进行筛选吧.我是这么想的可是问题是怎么筛选?
      

  2.   

    Hashtable hashtable = new Hashtable();
    Random rm = new Random();
    for(int i=0;hashtable.Count<7 ;i++)
    {
    int nValue = rm.Next(32);
    if(!hashtable.ContainsValue(nValue) && nValue!=0)
    {
    hashtable.Add(nValue,nValue);
    MessageBox.Show(nValue.ToString());
    }
    }