Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Server Code Submissions

Reply
 
Thread Tools Display Modes
  #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
  #2  
Old 04-22-2010, 05:45 PM
KLS
Administrator
 
Join Date: Sep 2006
Posts: 1,348
Default

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
Reply With Quote
  #3  
Old 04-22-2010, 06:06 PM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

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.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #4  
Old 05-09-2010, 10:41 PM
Wolftousen
Sarnak
 
Join Date: Apr 2008
Posts: 49
Default

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.
Reply With Quote
  #5  
Old 05-10-2010, 05:25 AM
mixxit
Hill Giant
 
Join Date: Sep 2006
Posts: 155
Default

my @moo = (221,222,223);
my $choice = rand @moo;
my $picked = $moo[$choice];

$moo = undef;
$choice = undef;
$picked = undef;
Reply With Quote
  #6  
Old 05-10-2010, 11:29 AM
gaeorn
Developer
 
Join Date: Apr 2009
Location: USA
Posts: 478
Default

Quote:
Originally Posted by Wolftousen View Post
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/~wagne...neTwister.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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 09:57 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3