From 95548cb1caad95933e2b36df9a13af070b733b04 Mon Sep 17 00:00:00 2001 From: gepard1984 Date: Tue, 17 Jan 2012 18:06:34 +0000 Subject: Enabled Mersenne Twister MT19937 as random number generator instead of standard `rand()` function (follow-up to r14865, r14870). - It fixes issues caused by RAND_MAX being only 32k in Windows system (bugreport:1927, bugreport:86). git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@15483 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/map.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/map/map.c') diff --git a/src/map/map.c b/src/map/map.c index c433857ec..fee813241 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -10,6 +10,7 @@ #include "../common/showmsg.h" #include "../common/version.h" #include "../common/nullpo.h" +#include "../common/random.h" #include "../common/strlib.h" #include "../common/utils.h" @@ -1270,7 +1271,7 @@ int map_searchrandfreecell(int m,int *x,int *y,int stack) } if(free_cell==0) return 0; - free_cell = rand()%free_cell; + free_cell = rnd()%free_cell; *x = free_cells[free_cell][0]; *y = free_cells[free_cell][1]; return 1; @@ -1331,8 +1332,8 @@ int map_search_freecell(struct block_list *src, int m, short *x,short *y, int rx } while(tries--) { - *x = (rx >= 0)?(rand()%rx2-rx+bx):(rand()%(map[m].xs-2)+1); - *y = (ry >= 0)?(rand()%ry2-ry+by):(rand()%(map[m].ys-2)+1); + *x = (rx >= 0)?(rnd()%rx2-rx+bx):(rnd()%(map[m].xs-2)+1); + *y = (ry >= 0)?(rnd()%ry2-ry+by):(rnd()%(map[m].ys-2)+1); if (*x == bx && *y == by) continue; //Avoid picking the same target tile. @@ -1373,7 +1374,7 @@ int map_addflooritem(struct item *item_data,int amount,int m,int x,int y,int fir if(!map_searchrandfreecell(m,&x,&y,flags&2?1:0)) return 0; - r=rand(); + r=rnd(); CREATE(fitem, struct flooritem_data, 1); fitem->bl.type=BL_ITEM; @@ -2310,8 +2311,8 @@ int map_random_dir(struct block_list *bl, short *x, short *y) if (dist < 1) dist =1; do { - j = 1 + 2*(rand()%4); //Pick a random diagonal direction - segment = 1+(rand()%dist); //Pick a random interval from the whole vector in that direction + j = 1 + 2*(rnd()%4); //Pick a random diagonal direction + segment = 1+(rnd()%dist); //Pick a random interval from the whole vector in that direction xi = bl->x + segment*dirx[j]; segment = (short)sqrt((float)(dist2 - segment*segment)); //The complement of the previously picked segment yi = bl->y + segment*diry[j]; @@ -3628,7 +3629,7 @@ int do_init(int argc, char *argv[]) MSG_CONF_NAME = "conf/msg_athena.conf"; GRF_PATH_FILENAME = "conf/grf-files.txt"; - srand(gettick()); + rnd_init(); for( i = 1; i < argc ; i++ ) { -- cgit v1.2.3-60-g2f50