question unsort(x)

new topic     » topic index » view thread      » older message » newer message

It is not a typical thing but now I need a routine that is simple, fast,
efficient and puts the elements of a sequence into random order. The best I could
come up with is this.

function unsort(sequence x)
	integer lx,px,py
	object bx
	lx=length(x)
	bx=x[1]
	x[1]=0
	py=1
	for i=1 to lx by 1 do
		px=rand(lx)
        	x[py]=x[px]
        	py=px
	end for
	x[py]=bx
	return x
end function


Any more efficient code? Any better idea? 

Thanks in advance!

Salix

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu