求一乱序算法!

zhanzhiyuan 2006-04-19 05:25:41
要求把数组中的顺序打乱。。越乱越好
...全文
200 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
aSalt 2006-04-19
  • 打赏
  • 举报
回复
直接拉(哈)稀了得了~~绝对乱地你找不到北,但相当~~~便于~~~拉的人查找

hash
real3000 2006-04-19
  • 打赏
  • 举报
回复
public class RandomRange
{
private int range = 0;
private object[] container;
private Random rand;

public RandomRange(object[] container)
{
this.container = container;
this.range = container.Length;

long time = DateTime.Now.Ticks;
string temp = Convert.ToString(time,2).PadLeft(64,'0');
string temp2 = temp.Substring(32,32);
int i = Convert.ToInt32(temp2,2);
rand = new Random(Convert.ToInt32(temp2,2));
}

public void DoRange()
{
int j = 0;
for(int i=0;i<range;i++)
{
j = rand.Next(range);
Switch(i,j);
}
}

private void Switch(int i,int j)
{
int temp = 0;
temp = container[i];
container[i] = container[j];
container[j] = temp;
}

public override string ToString()
{
StringBuilder sb = new StringBuilder();
for(int i=0;i<range;i++)
{
sb.Append(container[i].ToString());
sb.Append(" ");
}
return sb.ToString();
}
}
diandian82 2006-04-19
  • 打赏
  • 举报
回复
right,你没有一个乱的标准,万一乱完了正好是你看来最整齐的怎么办?
viena 2006-04-19
  • 打赏
  • 举报
回复
怎样才算乱呢?数组本身就是乱的
copico 2006-04-19
  • 打赏
  • 举报
回复
int[] intD =new int[10]{1,2,3,4,5,6,7,8,9,10};

int i,j;
for(j=0 ;j<10000;j++) //让它在里面搅1000次
{
Random rnd1 =new Random(10);//这个10按你数组的大小来定
Random rnd2 = new Random(10);
int a ,b,temp;
a=(int)rnd1;
b=(int)rnd2;
temp=intD[rnd1];
intD[rnd1]=intD[rnd2];
intD[rnd2]=temp;
}
RexZheng 2006-04-19
  • 打赏
  • 举报
回复
关注
kirc 2006-04-19
  • 打赏
  • 举报
回复
private void 乱序算法()
{
int[] iarr = new int[10]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Random r = new Random();
int pos, temp, lpos = 1;
for(int i=0; i<10; i++)
{
pos = r.Next(0, iarr.Length);
temp = iarr[pos];
iarr[pos] = iarr[lpos];
iarr[lpos] = temp;
lpos = pos;
}
}

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧