View Single Post
  #1  
Old 04-21-2010, 02:55 PM
Wolftousen
Sarnak
 
Join Date: Apr 2008
Posts: 49
Default Suggestion for perl quest random function

Code:
XS(XS__ChooseRandom);
XS(XS__ChooseRandom)
{
dXSARGS;
if (items < 1)
   Perl_croak(aTHX_ "Usage: ChooseRandom(... list ...)");

int random = MakeRandomInt(0, items * 10);
int index = random % items;

SV *tmp = ST(0);
ST(0) = ST(index);
ST(index) = tmp;

XSRETURN(1);   //return 1 element from the stack (ST(0))
}
instead of what it is... selecting from a larger pool gives "better" "random" results...
Reply With Quote