diff options
author | MadCamel <madcamel@gmail.com> | 2009-09-16 07:49:36 -0400 |
---|---|---|
committer | MadCamel <madcamel@gmail.com> | 2009-09-16 07:49:36 -0400 |
commit | 03149635727f16b45e99fd5f2f3647d6c4cb749f (patch) | |
tree | 4b9f06028bd79a152e485629e175b76447d33b98 /src | |
parent | d7b6afc444c1fac508dd5cc4bdf7e4dfa57e50c2 (diff) | |
download | tmwa-03149635727f16b45e99fd5f2f3647d6c4cb749f.tar.gz tmwa-03149635727f16b45e99fd5f2f3647d6c4cb749f.tar.bz2 tmwa-03149635727f16b45e99fd5f2f3647d6c4cb749f.tar.xz tmwa-03149635727f16b45e99fd5f2f3647d6c4cb749f.zip |
Found and replaced more calls to rand()
Diffstat (limited to 'src')
-rw-r--r-- | src/map/itemdb.c | 4 | ||||
-rw-r--r-- | src/map/magic-expr.c | 17 | ||||
-rw-r--r-- | src/map/mob.c | 2 | ||||
-rw-r--r-- | src/map/script.c | 2 |
4 files changed, 12 insertions, 13 deletions
diff --git a/src/map/itemdb.c b/src/map/itemdb.c index d9cb429..3b49b50 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -111,8 +111,8 @@ int itemdb_searchrandomid(int flags) if(count > 0) { for(i=0;i<1000;i++) { - index = rand()%count; - if( rand()%1000000 < list[index].per) { + index = MRAND(count); + if( MRAND(1000000) < list[index].per) { nameid = list[index].nameid; break; } diff --git a/src/map/magic-expr.c b/src/map/magic-expr.c index c136a17..9d3c751 100644 --- a/src/map/magic-expr.c +++ b/src/map/magic-expr.c @@ -607,8 +607,6 @@ fun_location(env_t *env, int args_nr, val_t *result, val_t *args) return 0; } -/* Recall that glibc's rand() isnt' too bad in the lower bits */ - static int fun_random(env_t *env, int args_nr, val_t *result, val_t *args) { @@ -619,7 +617,8 @@ fun_random(env_t *env, int args_nr, val_t *result, val_t *args) RESULTINT = 0; return 0; } - RESULTINT = rand() % delta; + RESULTINT = MRAND(delta); + if (ARGINT(0) < 0) RESULTINT = -RESULTINT; return 0; @@ -629,9 +628,9 @@ static int fun_random_dir(env_t *env, int args_nr, val_t *result, val_t *args) { if (ARGINT(0)) - RESULTDIR = rand() & 0x7; + RESULTDIR = mt_random() & 0x7; else - RESULTDIR = (rand() & 0x3) * 2; + RESULTDIR = (mt_random() & 0x3) * 2; return 0; } @@ -850,7 +849,7 @@ magic_random_location(location_t *dest, area_t *area) { switch (area->ty) { case AREA_UNION: { - int rv = rand() % area->size; + int rv = MRAND(area->size); if (rv < area->a.a_union[0]->size) magic_random_location(dest, area->a.a_union[0]); else @@ -870,14 +869,14 @@ magic_random_location(location_t *dest, area_t *area) if (h <= 1) h = 1; - x += rand() % w; - y += rand() % h; + x += MRAND(w); + y += MRAND(h); if (!map_is_solid(m, x, y)) { int start_x = x; int start_y = y; int i; - int initial_dir = rand() & 0x7; + int initial_dir = mt_random() & 0x7; int dir = initial_dir; /* try all directions, up to a distance to 10, for a free slot */ diff --git a/src/map/mob.c b/src/map/mob.c index f04ff28..cd74caa 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -1651,7 +1651,7 @@ static int mob_randomwalk(struct mob_data *md,int tick) int i,x,y,c,d=12-md->move_fail_count; if(d<5) d=5; for(i=0;i<retrycount;i++){ // Search of a movable place - int r=rand(); + int r=mt_random(); x=md->bl.x+r%(d*2+1)-d; y=md->bl.y+r/(d*2+1)%(d*2+1)-d; if((c=map_getcell(md->bl.m,x,y))!=1 && c!=5 && mob_walktoxy(md,x,y,1)==0){ diff --git a/src/map/script.c b/src/map/script.c index 40fcd62..8d9abe8 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -4147,7 +4147,7 @@ int buildin_sc_start2(struct script_state *st) bl = map_id2bl(st->rid); if(bl->type == BL_PC && ((struct map_session_data *)bl)->state.potionpitcher_flag) bl = map_id2bl(((struct map_session_data *)bl)->skilltarget); - if(rand()%10000 < per) + if(MRAND(10000) < per) skill_status_change_start(bl,type,val1,0,0,0,tick,0); return 0; } |