Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^5: Derangements iterator

by Jedaļ (Initiate)
on Dec 31, 2005 at 13:34 UTC ( #520145=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://520145]
help
Chatterbox?
[johngg]: Yes, must be nearly 30 years ago.
[hippo]: Loudest gig I can recall was Wolfsbane at the Astoria in the early 90s. Head rang for about 3 days afterwards. They were top, though.
[johngg]: My ears are still ringing!
Discipulus was outside The Clash concert in 1985..
[marto]: Wolfsbane , now I'm having flashbacks
[choroba]: Isn't Using PerlPod Creatively rather a meditation?
[choroba]: I don't see a question

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (13)
As of 2017-03-24 12:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (301 votes). Check out past polls.