PDA

View Full Version : Suggestion for perl quest random function


Wolftousen
04-21-2010, 02:55 PM
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...

KLS
04-22-2010, 05:45 PM
Not sure I quite understand, however perl has it's own rand functions that's quite useful if you want to write a plugin to do something with random that isn't provided by the code. So I don't really have to understand and implement it and you can still write it in perl.

http://perldoc.perl.org/functions/rand.html

trevius
04-22-2010, 06:06 PM
I already have a plugin for this:

http://www.eqemulator.org/forums/showthread.php?t=30421

You can create a new plugin file as it suggests, or just add it to any of your existing plugin files.

Wolftousen
05-09-2010, 10:41 PM
sorry i haven't checked these forums in a while, but what i was trying to do was get the function the quests call to get random values more diverse.

The root cause is really that eqemu is using the build in c random number generator. http://www-personal.umich.edu/~wagnerr/MersenneTwister.html is a far better choice and wouldn't take much at all to put into use.

mixxit
05-10-2010, 05:25 AM
my @moo = (221,222,223);
my $choice = rand @moo;
my $picked = $moo[$choice];

$moo = undef;
$choice = undef;
$picked = undef;

gaeorn
05-10-2010, 11:29 AM
sorry i haven't checked these forums in a while, but what i was trying to do was get the function the quests call to get random values more diverse.

The root cause is really that eqemu is using the build in c random number generator. http://www-personal.umich.edu/~wagnerr/MersenneTwister.html is a far better choice and wouldn't take much at all to put into use.
I am looking into this random number generator as I have noticed poor results with the existing implementation at times.