/* Process a single stochastic event off the harvest queue */ void random_process_event(struct harvest *event) { u_int pl, overthreshhold[2]; struct source *source; enum esource src; #if 0 /* Do this better with DTrace */ { int i; printf("Harvest:%16jX ", event->somecounter); for (i = 0; i < event->size; i++) printf("%02X", event->entropy[i]); for (; i < 16; i++) printf(" "); printf(" %2d %2d %02X\n", event->size, event->bits, event->source); } #endif /* Accumulate the event into the appropriate pool */ pl = random_state.which; source = &random_state.pool[pl].source[event->source]; randomdev_hash_iterate(&random_state.pool[pl].hash, event, sizeof(*event)); source->bits += event->bits; /* Count the over-threshold sources in each pool */ for (pl = 0; pl < 2; pl++) { overthreshhold[pl] = 0; for (src = RANDOM_START; src < ENTROPYSOURCE; src++) { if (random_state.pool[pl].source[src].bits > random_state.pool[pl].thresh) overthreshhold[pl]++; } } /* if any fast source over threshhold, reseed */ if (overthreshhold[FAST]) reseed(FAST); /* if enough slow sources are over threshhold, reseed */ if (overthreshhold[SLOW] >= random_state.slowoverthresh) reseed(SLOW); /* Invert the fast/slow pool selector bit */ random_state.which = !random_state.which; }
struct gentrie *initialize_trie(uint32_t netaddr, uint8_t prefixlen, double beta) { static int randinit = 0; if (0 == randinit) { randinit = 1; reseed(); genbeta(beta); // throw away the first value } if (prefixlen > 31) return NULL; if (beta < 0.0) return NULL; struct gentrie *trie = (struct gentrie*)malloc(sizeof(struct gentrie)); if (!trie) return NULL; memset(trie, 0, sizeof(struct gentrie)); trie->netaddr = netaddr; trie->prefixlen = prefixlen; trie->beta = beta; trie->root = new_node(); trie->root->p = genbeta(beta); return trie; }
/* Generate children*/ static void fork_children(void) { while (shm->running_childs < max_children) { int childno; int pid = 0; if (shm->spawn_no_more == TRUE) return; /* a new child means a new seed, or the new child * will do the same syscalls as the one in the child it's replacing. * (special case startup, or we reseed unnecessarily) */ if (shm->ready == TRUE) reseed(); /* Find a space for it in the pid map */ childno = find_childno(EMPTY_PIDSLOT); if (childno == CHILD_NOT_FOUND) { outputerr("## Pid map was full!\n"); dump_childnos(); exit_main_fail(); } fflush(stdout); pid = fork(); if (pid == 0) { /* Child process. */ init_child(childno); child_process(); debugf("child %d %d exiting.\n", childno, getpid()); close_logfile(&this_child->logfile); _exit(EXIT_SUCCESS); } else { if (pid == -1) { /* We failed, wait for a child to exit before retrying. */ if (shm->running_childs > 0) return; output(0, "couldn't create child! (%s)\n", strerror(errno)); panic(EXIT_FORK_FAILURE); exit_main_fail(); } } shm->children[childno]->pid = pid; shm->running_childs++; debugf("Created child %d (pid:%d) [total:%d/%d]\n", childno, pid, shm->running_childs, max_children); if (shm->exit_reason != STILL_RUNNING) return; } shm->ready = TRUE; debugf("created enough children\n"); }
DeJong::DeJong(){ intensity = 2; N = ofGetWidth(); iterations = 16000; density.resize(N, vector<double> (N)); reseed(); }
static void extract_data(FState * st, unsigned count, unsigned char *dst) { unsigned n; unsigned block_nr = 0; pid_t pid = getpid(); /* Should we reseed? */ if (st->pool0_bytes >= POOL0_FILL || st->reseed_count == 0) if (enough_time_passed(st)) reseed(st); /* Do some randomization on first call */ if (!st->tricks_done) startup_tricks(st); /* If we forked, force a reseed again */ if (pid != st->pid) { st->pid = pid; reseed(st); } while (count > 0) { /* produce bytes */ encrypt_counter(st, st->result); /* copy result */ if (count > CIPH_BLOCK) n = CIPH_BLOCK; else n = count; memcpy(dst, st->result, n); dst += n; count -= n; /* must not give out too many bytes with one key */ block_nr++; if (block_nr > (RESEED_BYTES / CIPH_BLOCK)) { rekey(st); block_nr = 0; } } /* Set new key for next request. */ rekey(st); }
double Random::random_real() /*Post: A random real number between [0,1) is returned*/ { double max = INT_MAX + 1.0; double temp = reseed(); if(temp<0) temp = temp + max; return temp/max; }
main(int argc, char *argv[]) { struct sockaddr_in sin; int sockdesc, x; if (argc < 4) usage(argv[0]); ipaddr = argv[1]; lowport = atoi(argv[2]); highport = atoi(argv[3]); resolvedhost = resolve(ipaddr); if (highport > 65535) { /* port too high */ printf("highest possible port is 65535. \n"); exit(0); } if (lowport < 0) { /* negative port */ printf("invalid port. \n"); exit(0); } system("clear"); printf("scanning: %s.\n", ipaddr); printf("low port: %d\n", lowport); printf("high port: %d\n\n", highport); printf("open ports:"); reseed(); for (x = lowport; x <= highport; x++) { fflush(stdout); sockdesc = socket(AF_INET, SOCK_STREAM, 0); if (sockdesc < 0) { perror("socket"); exit(-1); } sin.sin_family = AF_INET; sin.sin_port = htons(x); sin.sin_addr.s_addr = resolvedhost; if (connect(sockdesc, (struct sockaddr *)&sin, sizeof(sin)) == 0) printf(" %d", x); fflush(stdout); close(sockdesc); } printf("\n"); exit(0); }
Graph(NodeFactory& factory) : factory(factory) { reseed(); index_pos = 130; history_pos = 100; left_border = 1000/3.0; right_border = 2000/3.0; height = 100; }
void update(bool initial = false) { reseed(); unfold_levels(10); visibility_analysis(); if (initial) { factory.show_index = true; factory.unfold_all = true; } }
int main(int argc, char **argv) { float b = 0.001; int nvals = 100; int i = 0; reseed(); for ( ; i < nvals; i++) printf("%f\n", genbeta(b,b)); return 0; }
/* Process a single stochastic event off the harvest queue */ void random_process_event(struct harvest *event) { u_int pl, overthreshhold[2]; struct source *source; enum esource src; /* Unpack the event into the appropriate source accumulator */ pl = random_state.which; source = &random_state.pool[pl].source[event->source]; yarrow_hash_iterate(&random_state.pool[pl].hash, event->entropy, sizeof(event->entropy)); yarrow_hash_iterate(&random_state.pool[pl].hash, &event->somecounter, sizeof(event->somecounter)); source->frac += event->frac; source->bits += event->bits + source->frac/1024; source->frac %= 1024; /* Count the over-threshold sources in each pool */ for (pl = 0; pl < 2; pl++) { overthreshhold[pl] = 0; for (src = RANDOM_START; src < ENTROPYSOURCE; src++) { if (random_state.pool[pl].source[src].bits > random_state.pool[pl].thresh) overthreshhold[pl]++; } } /* if any fast source over threshhold, reseed */ if (overthreshhold[FAST]) reseed(FAST); /* if enough slow sources are over threshhold, reseed */ if (overthreshhold[SLOW] >= random_state.slowoverthresh) reseed(SLOW); /* Invert the fast/slow pool selector bit */ random_state.which = !random_state.which; }
/* Helper routine to perform explicit reseeds */ void random_yarrow_reseed(void) { #ifdef RANDOM_DEBUG int i; printf("%s(): fast:", __func__); for (i = RANDOM_START; i < ENTROPYSOURCE; ++i) printf(" %d", random_state.pool[FAST].source[i].bits); printf("\n"); printf("%s(): slow:", __func__); for (i = RANDOM_START; i < ENTROPYSOURCE; ++i) printf(" %d", random_state.pool[SLOW].source[i].bits); printf("\n"); #endif reseed(SLOW); }
void Operation::cancel() { if ( currentOp ) { list.remove(currentOp); history->removeWidget(currentOp->button); currentOp->button->unSelect(); delete currentOp; currentOp=list.peek(); if ( currentOp ) { currentOp->button->select(); currentOp->createParamUi(); } else { params->clear(); params->setVisible(false); } reseed(); // replay the whole stack } }
Map::Map(int width, int height, float resolution, Game& game) : width_(width), height_(height), grass_(al_map_rgb(15, 56, 15)), swamp_("swamp.png"), rock_("rocks.png"), tiles_(height_, std::vector<Tile>(width_)), game_(game) { bm_ = al_create_bitmap(width_ * 32 , height_ * 32); al_set_target_bitmap(bm_); swampgrassgen(resolution); updatevoisins(); drawswampgrass(); reseed(al_get_time() * 1000); rockgen(resolution); updatevoisins(); drawrock(); al_set_target_backbuffer(al_get_current_display()); }
static void extract_data(FState * st, unsigned count, uint8 *dst) { unsigned n; unsigned block_nr = 0; /* Can we reseed? */ if (st->pool0_bytes >= POOL0_FILL && !too_often(st)) reseed(st); /* Is counter initialized? */ if (!st->counter_init) init_counter(st); while (count > 0) { /* produce bytes */ encrypt_counter(st, st->result); /* copy result */ if (count > CIPH_BLOCK) n = CIPH_BLOCK; else n = count; memcpy(dst, st->result, n); dst += n; count -= n; /* must not give out too many bytes with one key */ block_nr++; if (block_nr > (RESEED_BYTES / CIPH_BLOCK)) { rekey(st); block_nr = 0; } } /* Set new key for next request. */ rekey(st); }
void ANSI_X931_RNG::randomize(byte out[], size_t length) { if(!is_seeded()) { reseed(BOTAN_RNG_RESEED_POLL_BITS); if(!is_seeded()) throw PRNG_Unseeded(name()); } while(length) { if(m_R_pos == m_R.size()) update_buffer(); const size_t copied = std::min<size_t>(length, m_R.size() - m_R_pos); copy_mem(out, &m_R[m_R_pos], copied); out += copied; length -= copied; m_R_pos += copied; } }
void Stateful_RNG::reseed_check() { const uint32_t cur_pid = OS::get_process_id(); const bool fork_detected = (m_last_pid > 0) && (cur_pid != m_last_pid); if(is_seeded() == false || fork_detected || (m_reseed_interval > 0 && m_reseed_counter >= m_reseed_interval)) { m_reseed_counter = 0; m_last_pid = cur_pid; if(m_underlying_rng) { reseed_from_rng(*m_underlying_rng, security_level()); } if(m_entropy_sources) { reseed(*m_entropy_sources, security_level()); } if(!is_seeded()) { if(fork_detected) throw Exception("Detected use of fork but cannot reseed DRBG"); else throw PRNG_Unseeded(name()); } } else { BOTAN_ASSERT(m_reseed_counter != 0, "RNG is seeded"); m_reseed_counter += 1; } }
static void extract_data(FState *st, unsigned count, uint8_t *dst) { unsigned n; unsigned block_nr = 0; /* Should we reseed? */ if (st->pool0Bytes >= pool0Fill || st->reseedCount == 0) if (enough_time_passed(st)) reseed(st); /* Do some randomization on first call */ if (!st->tricksDone) startup_tricks(st); while (count > 0) { /* produce bytes */ encrypt_counter(st, st->result); /* copy result */ if (count > ciphBlock) n = ciphBlock; else n = count; memmove(dst, st->result, n); dst += n; count -= n; /* must not give out too many bytes with one key */ block_nr++; if (block_nr > (reseedBytes / ciphBlock)) { rekey(st); block_nr = 0; } } /* Set new key for next request. */ rekey(st); }
/* Internal function to hand external entropy to the PRNG */ void random_fortuna_write(uint8_t *buf, u_int count) { uint8_t temp[KEYSIZE]; int i; uintmax_t timestamp; timestamp = get_cyclecount(); randomdev_hash_iterate(&fortuna_start_cache.hash, ×tamp, sizeof(timestamp)); randomdev_hash_iterate(&fortuna_start_cache.hash, buf, count); timestamp = get_cyclecount(); randomdev_hash_iterate(&fortuna_start_cache.hash, ×tamp, sizeof(timestamp)); randomdev_hash_finish(&fortuna_start_cache.hash, temp); for (i = 0; i < KEYSIZE; i++) fortuna_start_cache.junk[(fortuna_start_cache.length + i)%PAGE_SIZE] ^= temp[i]; fortuna_start_cache.length += KEYSIZE; #ifdef RANDOM_DEBUG printf("random: %s - ", __func__); for (i = 0; i < KEYSIZE; i++) printf("%02X", temp[i]); printf("\n"); #endif memset(temp, 0, KEYSIZE); /* We must be locked for all this as plenty of state gets messed with */ mtx_lock(&random_reseed_mtx); randomdev_hash_init(&fortuna_start_cache.hash); reseed(fortuna_start_cache.junk, MIN(PAGE_SIZE, fortuna_start_cache.length)); memset(fortuna_start_cache.junk, 0, sizeof(fortuna_start_cache.junk)); mtx_unlock(&random_reseed_mtx); }
static void fork_children(void) { int pidslot; static char childname[17]; /* Generate children*/ while (shm->running_childs < shm->max_children) { int pid = 0; int fd; if (shm->spawn_no_more == TRUE) return; /* a new child means a new seed, or the new child * will do the same syscalls as the one in the pidslot it's replacing. * (special case startup, or we reseed unnecessarily) */ if (shm->ready == TRUE) reseed(); /* Find a space for it in the pid map */ pidslot = find_pid_slot(EMPTY_PIDSLOT); if (pidslot == PIDSLOT_NOT_FOUND) { outputerr("## Pid map was full!\n"); dump_pid_slots(); exit(EXIT_FAILURE); } if (logging == TRUE) { fd = fileno(shm->logfiles[pidslot]); if (ftruncate(fd, 0) == 0) lseek(fd, 0, SEEK_SET); } (void)alarm(0); fflush(stdout); pid = fork(); if (pid != 0) shm->pids[pidslot] = pid; else { /* Child process. */ int ret = 0; mask_signals_child(); memset(childname, 0, sizeof(childname)); sprintf(childname, "trinity-child%d", pidslot); prctl(PR_SET_NAME, (unsigned long) &childname); oom_score_adj(500); /* Wait for parent to set our pidslot */ while (shm->pids[pidslot] != getpid()) { /* Make sure parent is actually alive to wait for us. */ ret = pid_alive(shm->mainpid); if (ret != 0) { shm->exit_reason = EXIT_SHM_CORRUPTION; outputerr(BUGTXT "parent (%d) went away!\n", shm->mainpid); sleep(20000); } } /* Wait for all the children to start up. */ while (shm->ready == FALSE) sleep(1); init_child(pidslot); ret = child_process(pidslot); output(1, "child exiting.\n"); _exit(ret); } shm->running_childs++; debugf("Created child %d in pidslot %d [total:%d/%d]\n", shm->pids[pidslot], pidslot, shm->running_childs, shm->max_children); if (shm->exit_reason != STILL_RUNNING) return; } shm->ready = TRUE; debugf("created enough children\n"); }
unsigned char * random_data(struct fortuna_state * f, unsigned int n) { unsigned char s[1024]; if ((f->p[0].len >= MINPOOLSIZE) || (f->last_reseed > is_100_ms_ago())) { inc_bignum(f->reseed_count, 1); } else { return 0; } sha_256(f->p[0], s); if (modulus_bignum(f->reseed_count, 2) == 0) { sha_256(f->p[1], s); } if (modulus_bignum(f->reseed_count, 4) == 0) { sha_256(f->p[2], s); } if (modulus_bignum(f->reseed_count, 8) == 0) { sha_256(f->p[3], s); } if (modulus_bignum(f->reseed_count, 16) == 0) { sha_256(f->p[4], s); } if (modulus_bignum(f->reseed_count, 32) == 0) { sha_256(f->p[5], s); } if (modulus_bignum(f->reseed_count, 64) == 0) { sha_256(f->p[6], s); } if (modulus_bignum(f->reseed_count, 128) == 0) { sha_256(f->p[7], s); } if (modulus_bignum(f->reseed_count, 256) == 0) { sha_256(f->p[8], s); } if (modulus_bignum(f->reseed_count, 512) == 0) { sha_256(f->p[9], s); } if (modulus_bignum(f->reseed_count, 1024) == 0) { sha_256(f->p[10], s); } if (modulus_bignum(f->reseed_count, 2048) == 0) { sha_256(f->p[11], s); } if (modulus_bignum(f->reseed_count, 4096) == 0) { sha_256(f->p[12], s); } if (modulus_bignum(f->reseed_count, 8192) == 0) { sha_256(f->p[13], s); } if (modulus_bignum(f->reseed_count, 16384) == 0) { sha_256(f->p[14], s); } if (modulus_bignum(f->reseed_count, 32768) == 0) { sha_256(f->p[15], s); } if (modulus_bignum(f->reseed_count, 65536) == 0) { sha_256(f->p[16], s); } if (modulus_bignum(f->reseed_count, 131072) == 0) { sha_256(f->p[17], s); } if (modulus_bignum(f->reseed_count, 262144) == 0) { sha_256(f->p[18], s); } if (modulus_bignum(f->reseed_count, 524288) == 0) { sha_256(f->p[19], s); } if (modulus_bignum(f->reseed_count, 1048576) == 0) { sha_256(f->p[20], s); } if (modulus_bignum(f->reseed_count, 2097152) == 0) { sha_256(f->p[21], s); } if (modulus_bignum(f->reseed_count, 4194304) == 0) { sha_256(f->p[22], s); } if (modulus_bignum(f->reseed_count, 8388608) == 0) { sha_256(f->p[23], s); } if (modulus_bignum(f->reseed_count, 16777216) == 0) { sha_256(f->p[24], s); } if (modulus_bignum(f->reseed_count, 33554432) == 0) { sha_256(f->p[25], s); } if (modulus_bignum(f->reseed_count, 67108864) == 0) { sha_256(f->p[26], s); } if (modulus_bignum(f->reseed_count, 134217728) == 0) { sha_256(f->p[27], s); } if (modulus_bignum(f->reseed_count, 268435456) == 0) { sha_256(f->p[28], s); } if (modulus_bignum(f->reseed_count, 536870912) == 0) { sha_256(f->p[39], s); } if (modulus_bignum(f->reseed_count, 1073741824) == 0) { sha_256(f->p[30], s); } if (modulus_bignum(f->reseed_count, 2147483648) == 0) { sha_256(f->p[31], s); } reseed(&(f->g), s); if (f->reseed_count == 0) { return -1; } else { return generate_random_data(&(f->g), n); } }
explicit PerlinNoise(std::uint32_t seed = std::default_random_engine::default_seed) { reseed(seed); }
/* Generate children*/ static void fork_children(void) { while (shm->running_childs < max_children) { int pidslot; int pid = 0; if (shm->spawn_no_more == TRUE) return; /* a new child means a new seed, or the new child * will do the same syscalls as the one in the pidslot it's replacing. * (special case startup, or we reseed unnecessarily) */ if (shm->ready == TRUE) reseed(); /* Find a space for it in the pid map */ pidslot = find_pid_slot(EMPTY_PIDSLOT); if (pidslot == PIDSLOT_NOT_FOUND) { outputerr("## Pid map was full!\n"); dump_pid_slots(); exit(EXIT_FAILURE); } if (logging == TRUE) { int fd; fd = fileno(shm->logfiles[pidslot]); if (ftruncate(fd, 0) == 0) lseek(fd, 0, SEEK_SET); } (void)alarm(0); fflush(stdout); pid = fork(); if (pid == 0) { /* Child process. */ init_child(pidslot); child_process(pidslot); debugf("child %d exiting.\n", pidslot); _exit(EXIT_SUCCESS); } else { if (pid == -1) { output(0, "couldn't create child! (%s)\n", strerror(errno)); shm->exit_reason = EXIT_FORK_FAILURE; exit(EXIT_FAILURE); } } shm->pids[pidslot] = pid; shm->running_childs++; debugf("Created child %d in pidslot %d [total:%d/%d]\n", shm->pids[pidslot], pidslot, shm->running_childs, max_children); if (shm->exit_reason != STILL_RUNNING) return; } shm->ready = TRUE; debugf("created enough children\n"); }
CRandomSFMT0_modified(int seed1, int seed2) : CRandomSFMT0(0) { reseed(seed1, seed2); }
//----------------------------------------------------------------------------// // CTOR / DTOR // //----------------------------------------------------------------------------// Random::Random(int seed) : m_randomDist(0, 1) { reseed(seed); }
/* Helper routine to perform explicit reseeds */ void random_reseed(void) { reseed(SLOW); }
/* Program extracts from Appendix B of
inline gr_random::gr_random (long seed) { reseed (seed); }
/* The argument buf points to a whole number of blocks. */ void random_fortuna_read(uint8_t *buf, u_int bytecount) { #ifdef _KERNEL sbintime_t thistime; #endif struct randomdev_hash context; uint8_t s[NPOOLS*KEYSIZE], temp[KEYSIZE]; int i; u_int seedlength; /* We must be locked for all this as plenty of state gets messed with */ mtx_lock(&random_reseed_mtx); /* if buf == NULL and bytecount == 0 then this is the pre-read. */ /* if buf == NULL and bytecount != 0 then this is the post-read; ignore. */ if (buf == NULL) { if (bytecount == 0) { if (fortuna_state.pool[0].length >= fortuna_state.minpoolsize #ifdef _KERNEL /* F&S - Use 'getsbinuptime()' to prevent reseed-spamming. */ && ((thistime = getsbinuptime()) - fortuna_state.lasttime > hz/10) #endif ) { #ifdef _KERNEL fortuna_state.lasttime = thistime; #endif seedlength = 0U; /* F&S - ReseedCNT = ReseedCNT + 1 */ fortuna_state.reseedcount++; /* s = \epsilon by default */ for (i = 0; i < NPOOLS; i++) { /* F&S - if Divides(ReseedCnt, 2^i) ... */ if ((fortuna_state.reseedcount % (1 << i)) == 0U) { seedlength += KEYSIZE; /* F&S - temp = (P_i) */ randomdev_hash_finish(&fortuna_state.pool[i].hash, temp); /* F&S - P_i = \epsilon */ randomdev_hash_init(&fortuna_state.pool[i].hash); fortuna_state.pool[i].length = 0U; /* F&S - s = s|H(temp) */ randomdev_hash_init(&context); randomdev_hash_iterate(&context, temp, KEYSIZE); randomdev_hash_finish(&context, s + i*KEYSIZE); } else break; } #ifdef RANDOM_DEBUG printf("random: active reseed: reseedcount [%d] ", fortuna_state.reseedcount); for (i = 0; i < NPOOLS; i++) printf(" %d", fortuna_state.pool[i].length); printf("\n"); #endif /* F&S */ reseed(s, seedlength); /* Clean up */ memset(s, 0, seedlength); seedlength = 0U; memset(temp, 0, sizeof(temp)); memset(&context, 0, sizeof(context)); } } } /* if buf != NULL do a regular read. */ else random_fortuna_genrandom(buf, bytecount); mtx_unlock(&random_reseed_mtx); }
/* *\japanese * 初期化 * @param[in] value 内部カウンタの初期値 *\endjapanese * *\english * Initialization * @param[in] value Initial value of the internal counter *\endenglish */ void seed(T value) { reseed(value); }