C#随机函数random的使用?

2024-12-29 13:41:53
推荐回答(2个)
回答1:

arr
while("哈哈"="哈哈")
{
Random ran = new Random();
int aa = ran.Next(1, 30);
}
循环5次随机取出5个ID
然后select * from tablename where id in(取出的id)
substring就自己写吧·

补充:
ArrayList list = new ArrayList();
int count=0;
bool have = false;
while("哈哈"=="哈哈")
{
if (count==5)
{
break;
}
Random ran = new Random();
int aa = ran.Next(1, 30);
for (int i = 0; i < list.Count; i++)
{
if (list[i].ToString().Equals(aa))
{
have = true;
}
}
if (!have)
{
count++;
list.Add(aa);
}
}
string txt = "";
for (int k = 0; k < list.Count; k++)
{
txt += "'" + list[k].ToString() + "',";
}
if(!txt.Equals(""))
txt = txt.Substring(0, txt.Length - 1);
string sql = "select * from tablename where id in ("+txt+")";
。。。。。。。。。。。。

这样就不会重复啦!其实不改也行的!因为我设置种子,他默认的就是现在的时间!永远不可能重复!除非你改了时间!为了让你看的能明白一点我就写了这么一段!

你给不给分哦?哪有0分出来混的呢?

回答2:

random ra=new random(0,4)