Index: sys/geom/multipath/g_multipath.c =================================================================== --- sys/geom/multipath/g_multipath.c +++ sys/geom/multipath/g_multipath.c @@ -898,7 +898,7 @@ sc = gp1->softc; if (gp == NULL) { char buf[16]; - u_long rand = random(); + u_long rand = arc4random(); snprintf(buf, sizeof (buf), "%s-%lu", md.md_name, rand); printf("GEOM_MULTIPATH: geom %s/%s exists already\n", Index: sys/kern/kern_fail.c =================================================================== --- sys/kern/kern_fail.c +++ sys/kern/kern_fail.c @@ -568,7 +568,7 @@ continue; if (ent->fe_prob < PROB_MAX && - ent->fe_prob < random() % PROB_MAX) + ent->fe_prob < arc4random() % PROB_MAX) continue; if (ent->fe_pid != NO_PID && ent->fe_pid != curproc->p_pid) Index: sys/kern/kern_synch.c =================================================================== --- sys/kern/kern_synch.c +++ sys/kern/kern_synch.c @@ -607,7 +607,7 @@ * run at regular intervals. */ callout_reset_sbt(&loadav_callout, - SBT_1US * (4000000 + (int)(random() % 2000001)), SBT_1US, + SBT_1US * (4000000 + (arc4random() % 2000001)), SBT_1US, loadav, NULL, C_DIRECT_EXEC | C_PREL(32)); } Index: sys/kern/subr_fattime.c =================================================================== --- sys/kern/subr_fattime.c +++ sys/kern/subr_fattime.c @@ -273,9 +273,9 @@ for (i = 0; i < 10000; i++) { do { - ts.tv_sec = random(); + ts.tv_sec = arc4random(); } while (ts.tv_sec < T1980 * 86400); - ts.tv_nsec = random() % 1000000000; + ts.tv_nsec = arc4random() % 1000000000; printf("%10d.%03ld -- ", ts.tv_sec, ts.tv_nsec / 1000000); Index: sys/net/altq/altq_classq.h =================================================================== --- sys/net/altq/altq_classq.h +++ sys/net/altq/altq_classq.h @@ -161,7 +161,7 @@ else { struct mbuf *prev = NULL; - n = random() % qlen(q) + 1; + n = arc4random() % qlen(q) + 1; for (i = 0; i < n; i++) { prev = m; m = m->m_nextpkt; Index: sys/net/if_spppfr.c =================================================================== --- sys/net/if_spppfr.c +++ sys/net/if_spppfr.c @@ -44,9 +44,6 @@ #include #include #include -#if defined(__FreeBSD__) -#include -#endif #include #include @@ -536,7 +533,7 @@ if (h[5] == FR_MSG_ENQUIRY) { if (len == FR_ENQUIRY_SIZE && h[12] == (u_char) sp->pp_seq[IDX_LCP]) { - sp->pp_seq[IDX_LCP] = random(); + sp->pp_seq[IDX_LCP] = arc4random(); printf (SPP_FMT "loopback detected\n", SPP_ARGS(ifp)); } Index: sys/net/if_spppsubr.c =================================================================== --- sys/net/if_spppsubr.c +++ sys/net/if_spppsubr.c @@ -1334,7 +1334,7 @@ ++sp->pp_loopcnt; /* Generate new local sequence number */ - sp->pp_seq[IDX_LCP] = random(); + sp->pp_seq[IDX_LCP] = arc4random(); break; } sp->pp_loopcnt = 0; @@ -2575,7 +2575,7 @@ if (magic == ~sp->lcp.magic) { if (debug) log(-1, "magic glitch "); - sp->lcp.magic = random(); + sp->lcp.magic = arc4random(); } else { sp->lcp.magic = magic; if (debug) @@ -2756,7 +2756,7 @@ if (sp->lcp.opts & (1 << LCP_OPT_MAGIC)) { if (! sp->lcp.magic) - sp->lcp.magic = random(); + sp->lcp.magic = arc4random(); opt[i++] = LCP_OPT_MAGIC; opt[i++] = 6; opt[i++] = sp->lcp.magic >> 24; @@ -4281,7 +4281,7 @@ * Compute the re-challenge timeout. This will yield * a number between 300 and 810 seconds. */ - i = 300 + ((unsigned)(random() & 0xff00) >> 7); + i = 300 + ((unsigned)(arc4random() & 0xff00) >> 7); callout_reset(&sp->ch[IDX_CHAP], i * hz, chap.TO, (void *)sp); } Index: sys/netgraph/ng_pipe.c =================================================================== --- sys/netgraph/ng_pipe.c +++ sys/netgraph/ng_pipe.c @@ -776,7 +776,7 @@ * the original packet... */ if (hinfo->cfg.duplicate && - random() % 100 <= hinfo->cfg.duplicate) { + arc4random() % 100 <= hinfo->cfg.duplicate) { ngp_h = uma_zalloc(ngp_zone, M_NOWAIT); KASSERT(ngp_h != NULL, ("ngp_h zalloc failed (3)")); m = m_dup(m, M_NOWAIT); @@ -819,7 +819,7 @@ /* Randomly discard the frame, according to BER setting */ if (hinfo->cfg.ber) { oldrand = rand; - rand = random(); + rand = arc4random(); if (((oldrand ^ rand) << 17) >= hinfo->ber_p[priv->overhead + m->m_pkthdr.len]) { hinfo->stats.out_disc_frames++; Index: sys/netinet/cc/cc_cdg.c =================================================================== --- sys/netinet/cc/cc_cdg.c +++ sys/netinet/cc/cc_cdg.c @@ -500,7 +500,7 @@ static inline int prob_backoff(long qtrend) { - int backoff, idx, p; + u_int backoff, idx, p; backoff = (qtrend > ((MAXGRAD * V_cdg_exp_backoff_scale) << D_P_E)); @@ -512,8 +512,8 @@ idx = qtrend; /* Backoff probability proportional to rate of queue growth. */ - p = (INT_MAX / (1 << EXP_PREC)) * probexp[idx]; - backoff = (random() < p); + p = (UINT_MAX / (1 << EXP_PREC)) * probexp[idx]; + backoff = (arc4random() < p); } return (backoff); Index: sys/netinet/cc/cc_chd.c =================================================================== --- sys/netinet/cc/cc_chd.c +++ sys/netinet/cc/cc_chd.c @@ -84,8 +84,8 @@ */ #define CC_CHD_DELAY 0x02000000 -/* Largest possible number returned by random(). */ -#define RANDOM_MAX INT_MAX +/* Largest possible number returned by arc4random(). */ +#define RANDOM_MAX UINT_MAX static void chd_ack_received(struct cc_var *ccv, uint16_t ack_type); static void chd_cb_destroy(struct cc_var *ccv); @@ -158,7 +158,7 @@ { unsigned long p, rand; - rand = random(); + rand = arc4random(); if (qdly < V_chd_qthresh) { chd_data->loss_compete = 0; Index: sys/netinet/cc/cc_hd.c =================================================================== --- sys/netinet/cc/cc_hd.c +++ sys/netinet/cc/cc_hd.c @@ -79,8 +79,8 @@ #include -/* Largest possible number returned by random(). */ -#define RANDOM_MAX INT_MAX +/* Largest possible number returned by arc4random(). */ +#define RANDOM_MAX UINT_MAX static void hd_ack_received(struct cc_var *ccv, uint16_t ack_type); static int hd_mod_init(void); @@ -119,7 +119,7 @@ p = (RANDOM_MAX / 100) * V_hd_pmax; } - return (random() < p); + return (arc4random() < p); } /* Index: sys/netpfil/ipfw/ip_dn_io.c =================================================================== --- sys/netpfil/ipfw/ip_dn_io.c +++ sys/netpfil/ipfw/ip_dn_io.c @@ -405,7 +405,7 @@ if (fs->fs.flags & DN_QSIZE_BYTES) p_b = div64((p_b * len) , fs->max_pkt_size); if (++q->count == 0) - q->random = random() & 0xffff; + q->random = arc4random() & 0xffff; else { /* * q->count counts packets arrived since last drop, so a greater @@ -414,7 +414,7 @@ if (SCALE_MUL(p_b, SCALE((int64_t)q->count)) > q->random) { q->count = 0; /* After a drop we calculate a new random value. */ - q->random = random() & 0xffff; + q->random = arc4random() & 0xffff; return (1); /* drop */ } } @@ -511,7 +511,7 @@ ni->tot_pkts++; if (drop) goto drop; - if (f->plr && random() < f->plr) + if (f->plr && (int32_t)arc4random() < f->plr) goto drop; #ifdef NEW_AQM /* Call AQM enqueue function */ @@ -583,7 +583,7 @@ if (!pf || pf->samples_no == 0) return 0; - index = random() % pf->samples_no; + index = arc4random() % pf->samples_no; bits = div64((uint64_t)pf->samples[index] * s->link.bandwidth, 1000); if (index >= pf->loss_level) { struct dn_pkt_tag *dt = dn_tag_get(m); Index: sys/netpfil/ipfw/ip_dn_private.h =================================================================== --- sys/netpfil/ipfw/ip_dn_private.h +++ sys/netpfil/ipfw/ip_dn_private.h @@ -265,7 +265,7 @@ /* RED parameters */ int avg; /* average queue length est. (scaled) */ int count; /* arrivals since last RED drop */ - int random; /* random value (scaled) */ + u_int random; /* random value (scaled) */ uint64_t q_time; /* start of queue idle time */ #ifdef NEW_AQM void *aqm_status; /* per-queue status variables*/ Index: sys/vm/memguard.c =================================================================== --- sys/vm/memguard.c +++ sys/vm/memguard.c @@ -447,7 +447,7 @@ if ((memguard_options & MG_GUARD_ALLLARGE) != 0 && size >= PAGE_SIZE) return (1); if (memguard_frequency > 0 && - (random() % 100000) < memguard_frequency) { + (arc4random() % 100000) < memguard_frequency) { memguard_frequency_hits++; return (1); }