吴
吴剑明
Unregistered / Unconfirmed
GUEST, unregistred user!
我下午就要。哪个大哥有现成算法给一份。我马上要的。
function random(maxstep)
{
return Math.round(Math.random()*maxstep);
}
// init chain array
var chain= new Array(500);
for (i=0;i<chain.length;i++)
{
chain[i] = i+1;
}
chain[chain.length-1]=0;
var pointer = 0;
var output= new Array();
var s='';
// select 200 random.
for (i=0;i<200;i++)
{
step = random(20);
for (j=0;j<step;j++)
{
// walk through the chain
pointer = chain[pointer];
}
// got it!
output[output.length]=chain[pointer];
s+=chain[pointer]+",";
chain[pointer]=chain[chain[pointer]];
}