http://qs321.pair.com?node_id=520145


in reply to Re^4: Derangements iterator
in thread Derangements iterator

Oops.. Sorry, the wrapper performs unnecessary operations, here a good version :
use Inline C => <<'END_OF_C_CODE'; void cderange ( SV* truc, ... ){ SV* sv_temp; I32 index, i; Inline_Stack_Vars; srand(time( NULL )); index = Inline_Stack_Items; for (; index; index--) { i = (I32) (rand() % (index)); sv_temp = Inline_Stack_Item(index); Inline_Stack_Item(index) = Inline_Stack_Item(i); Inline_Stack_Item(i) = sv_temp; } Inline_Stack_Done; } END_OF_C_CODE
Very fast, but this code is subject to the same caveat as Algorithm::Numerical::Shuffle.