From: Richard J. <ri...@an...> - 2005-12-07 12:40:04
|
Here are a couple more functions which I propose for addition to ExtArray: (* Swap two elements in an array. *) let swap xs i j = if i <> j then ( let c = xs.(i) in xs.(i) <- xs.(j); xs.(j) <- c ) (* Randomize an array (in place). *) let unsort xs = let n = Array.length xs in for i = 0 to n-2 do let j = Random.int (n - i) in swap xs i j done If you like those, then one for ExtList: (* Randomize a list. *) let unsort xs = let xs = Array.of_list xs in Array.unsort xs; Array.to_list xs Rich. -- Richard Jones, CTO Merjis Ltd. Merjis - web marketing and technology - http://merjis.com Team Notepad - intranets and extranets for business - http://team-notepad.com |