static void fill(TYPE *dst, const size_t size) { size_t i; for (i = 0; i < size; i++) { dst[i] = lrand48(); } }
long random_num (long min, long max) { long range, rand_num; range = max - min + 1; rand_num = lrand48 () % range; return rand_num + min; }
/*---------------------------------------------------------------------*/ tree_cell * nasl_rand(lex_ctxt * lexic) { tree_cell * retc; retc = alloc_tree_cell(0, NULL); retc->type = CONST_INT; retc->x.i_val = lrand48(); return retc; }
Foam::label Foam::osRandomInteger() { #ifdef USE_RANDOM return random(); #else return lrand48(); #endif }
label Random::integer(const label lower, const label upper) { # ifdef USE_RANDOM return lower + (random() % (upper+1-lower)); # else return lower + (lrand48() % (upper+1-lower)); # endif }
void armas_sched_schedule(armas_scheduler_t *S, armas_task_t *T) { int k, j; if (!S->status) { armas_sched_start(S); } // scheduling ARMAS_SCHED_WORKERS, write directly to worker queues. S->nsched++; if (S->nworker == 1) { T->wcnt = 1; taskq_write(&S->workers[0].inqueue, T); return; } if (S->opts & ARMAS_OSCHED_TWO) { T->wcnt = 2; if (S->nworker == 2) { taskq_write(&S->workers[0].inqueue, T); taskq_write(&S->workers[1].inqueue, T); return; } if ((S->opts & ARMAS_OSCHED_ROUNDROBIN) != 0) { k = S->rrindex; S->rrindex = (S->rrindex + 1) % S->nworker; j = S->rrindex; S->rrindex = (S->rrindex + 1) % S->nworker; } else { k = lrand48() % S->nworker; for (j = k; j == k; j = lrand48() % S->nworker); } taskq_write(&S->workers[k].inqueue, T); taskq_write(&S->workers[j].inqueue, T); return; } T->wcnt = 1; if ((S->opts & ARMAS_OSCHED_ROUNDROBIN) != 0) { k = S->rrindex; S->rrindex = (S->rrindex + 1) % S->nworker; } else { k = lrand48() % S->nworker; } taskq_write(&S->workers[k].inqueue, T); }
/*** nht_internal_CreateCookie - generate a random string value that can *** be used as an HTTP cookie. ***/ int nht_internal_CreateCookie(char* ck) { int i; /*printf("CreateCk called, stack ptr = %8.8X\n",&i);*/ sprintf(ck,"LS-%6.6X%4.4X", (((int)(time(NULL)))&0xFFFFFF), (((int)(lrand48()))&0xFFFF)); return 0; }
long RandomNumber() { #ifdef TARGET_OS_WINDOWS return (((holdrand = holdrand * 214013L + 2531011L) >> 16) & 0x7fff); #else return lrand48(); #endif }
struct rpc_target *rpc_target_alloc (struct process_id PID) { struct rpc_target *S = zmalloc (sizeof (*S)); S->PID = PID; S->target = 0; S->first = S->last = (struct connection *)S; S->inbound_num = 0; rpc_target_tree = tree_insert_rpc_target (rpc_target_tree, S, lrand48 ()); return S; }
static void rpc_header(struct client *clnt, struct rpc *rpc) { (void)clnt; rpc->call->hdr.frag_hdr = htonl(LAST_FRAG | (rpc->call_len - 4)); rpc->call->hdr.udp.xid = lrand48(); rpc->call->hdr.udp.msg_type = htonl(RPC_CALL); rpc->call->rpc_vers = htonl(2); }
void bench_lrand48(register iter_t iterations, void *cookie) { register long v = 0.0; while (iterations-- > 0) { v += lrand48(); } use_int((int)v); }
// randomly make a tree with the total number of nodes specified, not done Tree* randTree(unsigned long tot) { if (tot <= 0) return NULL; Tree *t = (Tree *)malloc(sizeof(Tree)); t->val = lrand48() % 1000; tot --; int i; for (i = 0; i < MAX_BRANCH - 1; i++) { // Choose randomly how many nodes to put in this subtree unsigned long nchildren = lrand48() % (tot + 1); t->child[i] = randTree(nchildren); tot -= nchildren; } // In the last subtree, use them all t->child[i] = randTree(tot); return t; }
int lo3r(int max) { int res1, res2, res3; return lrand48() % max; res1 = lrand48() % max; res2 = lrand48() % max; res3 = lrand48() % max; if(res1 < res2 && res1 < res3) return res1; if(res2 < res3) return res2; return res3; }
static int randomise_int(int max) { int r; struct timeval tv; gettimeofday(&tv, NULL); srand48((long)tv.tv_usec); r = (int)(((double)lrand48()/(double)RAND_MAX) * max); return r; }
static void fill_swapped(int64_t *dst, const int size, const swapped_cnt) { int i, tmp; size_t ind1, ind2; fill_sorted(dst, size); for (i = 0; i < swapped_cnt; i++) { ind1 = lrand48(); RAND_RANGE(ind1, 0, size); ind2 = lrand48(); RAND_RANGE(ind2, 0, size); tmp = dst[ind1]; dst[ind1] = dst[ind2]; dst[ind2] = tmp; } }
// knuth void shuffle(int *idx, int n) { for (int ii = 0; ii < (1<<4); ii++) { for (int i = 0; i < n-1; i++) { int v = idx[i]; int ii = (i+1) + (lrand48() % (n-(i+1))); idx[i] = idx[ii]; idx[ii] = v; } } }
bool random_bit () { static unsigned buffer=0, mask=0; mask >>= 1; if (not mask) { buffer = lrand48(); mask = 1<<30; } return buffer & mask; }
void testValues() { f = 2; long result; result = lrand48(); //@ assert 0 <= result < 2147483648; //@ assert f == 2; //@ assert vacuous: \false; }
static int randomise_port() { int r; struct timeval tv; gettimeofday(&tv, NULL); srand48((long)tv.tv_usec); r = (int)(((double)lrand48()/(double)RAND_MAX) * 1000); return RGET_PORT_BASE + r; }
static unsigned randpos(struct state *s) { unsigned n; #ifdef USE_DEV_URANDOM read(randfd, &n, sizeof(n)); #else n = lrand48(); #endif s = s; return n % bc; }
int websocket_msg_handler(mtev_websocket_client_t *client, int opcode, const unsigned char *msg, size_t msg_len) { char buf[256]; size_t len; snprintf(buf, msg_len, "%s", msg); mtevL(mtev_error, "I received a message! %s\n", buf); len = snprintf(buf, sizeof(buf), "%ld", lrand48()); mtev_websocket_client_send(client, opcode, buf, len); return 0; }
static int get_b_rand(void) { static int ph=32; /* More bits than we will ever use */ static unsigned long randseq; if(ph > 31) { /* Num bits in return of lrand48() */ ph=0; randseq = lrand48(); } ph++; return ((randseq & (1 << (ph-1))) >> (ph-1)); }
ATF_TC_BODY(setenv_basic, tc) { const size_t numvars = 8192; size_t i, offset; char name[1024]; char value[1024]; offset = lrand48(); for (i = 0; i < numvars; i++) { (void)snprintf(name, sizeof(name), "var%zu", (i * 7 + offset) % numvars); (void)snprintf(value, sizeof(value), "value%ld", lrand48()); ATF_CHECK(setenv(name, value, 1) != -1); ATF_CHECK(setenv(name, "foo", 0) != -1); ATF_CHECK_STREQ(getenv(name), value); } offset = lrand48(); for (i = 0; i < numvars; i++) { (void)snprintf(name, sizeof(name), "var%zu", (i * 11 + offset) % numvars); ATF_CHECK(unsetenv(name) != -1); ATF_CHECK(getenv(name) == NULL); ATF_CHECK(unsetenv(name) != -1); } ATF_CHECK_ERRNO(EINVAL, setenv(NULL, "val", 1) == -1); ATF_CHECK_ERRNO(EINVAL, setenv("", "val", 1) == -1); ATF_CHECK_ERRNO(EINVAL, setenv("v=r", "val", 1) == -1); #ifdef __FreeBSD__ /* Both FreeBSD and OS/X does not validate the second argument to setenv(3) */ atf_tc_expect_signal(SIGSEGV, "FreeBSD does not validate the second " "argument to setenv(3); see bin/189805"); #endif ATF_CHECK_ERRNO(EINVAL, setenv("var", NULL, 1) == -1); ATF_CHECK(setenv("var", "=val", 1) == 0); ATF_CHECK_STREQ(getenv("var"), "=val"); }
// // void InitData(void); // // do this in single-thread mode // void InitData(void){ int i; gMem = (GlobalMemory *)malloc(sizeof(GlobalMemory)); if(gMem == NULL){ fprintf(stderr, "Unable to allocate memory for gMem\n"); exit(-1); } memset(gMem, '\0', sizeof(gMem)); // Create locks and give hints. if (!quiet){ printf("\tROOT: Creating locks, barriers, and condition vars.\n"); } #ifdef NOTDEF // Chuck's comments: not defined in the source code? // not sure if they are part of TMK system call //TaskStackLock = CreateLock(); // Lock number 0x1000 //AssociateDataAndSynch(TaskStack, TaskStackLock); //AssociateDataAndSynch(&gMem->TaskStackTop, TaskStackLock); #endif // NOTDEF INITPAUSE(pauseFlag, 2); gMem->TaskStackLock = 1; // All of the elements are unique. for (i = 0; i < size; i++){ gMem->A[i] = i; } //Shuffle data randomly. #ifdef SWAP for (i = 0; i < size; i++) { SWAP(gMem->A, i, (lrand48() % (size-i)) + i); } #else for (i = 0; i < size; i++) { Swap(i, (random() % (size-i)) + i); } #endif gMem->TaskStackTop = 0; gMem->NumWaiting = 0; // Special: On this node, there are *2* threads (worker and master). if (!quiet){ printf("\tSorting %d-entry array on %d procs! Bubble thresh: %d.\n", size, Tmk_nprocs, BubbleThresh); } // Push the initial value. PushWork(0, size-1); }
// ================================================================================== // main // ================================================================================== int main(int argc, char *argv[]){ // Handle parameter if(argc != 2 && argc != 3){ fprintf(stderr, USAGE_MESSAGE, argv[0]); return EXIT_FAILURE; } size_t N = atoi(argv[1]); // Create N nodes node_t *nodes = calloc(N, sizeof(node_t)); int i, j, distance; int edge_count = 0; srand48(time(NULL)); for(i=0; i<(N-1); ++i){ for(j=i+1; j<N; ++j){ // Add edges distance = lrand48() % RANGE_MAX + 1; add_edge(&(nodes[i].edge_head), &nodes[j], distance); add_edge(&(nodes[j].edge_head), &nodes[i], distance); edge_count++; } } // Print nodes with edges before dijkstra if(argc == 3){ printf("Nodes before dijkstra\n"); for(i=0; i<N; ++i){ print_node(&nodes[i]); } printf("\n"); } // Measure time clock_t begin, end; double time_spent; printf("Starting dijkstra for problem size (node) %zu and %i edges\n", N, edge_count); begin = clock(); dijsktra(nodes, N, &nodes[0]); end = clock(); time_spent = (double)(end - begin) / CLOCKS_PER_SEC; printf("Time spent: %fs\n", time_spent); // Free memory for(i=0; i<N; ++i){ // Print nodes after dijkstra if(argc == 3){ printf("\nNodes after dijkstra:\n"); print_node(&nodes[i]); } free_edges(nodes[i].edge_head); } free(&nodes[0]); return EXIT_SUCCESS; }
static int32_t FcRandom(void) { int32_t result; #if HAVE_RANDOM_R static struct random_data fcrandbuf; static char statebuf[256]; static FcBool initialized = FcFalse; if (initialized != FcTrue) { initstate_r(time(NULL), statebuf, 256, &fcrandbuf); initialized = FcTrue; } random_r(&fcrandbuf, &result); #elif HAVE_RANDOM static char statebuf[256]; char *state; static FcBool initialized = FcFalse; if (initialized != FcTrue) { state = initstate(time(NULL), statebuf, 256); initialized = FcTrue; } else state = setstate(statebuf); result = random(); setstate(state); #elif HAVE_LRAND48 result = lrand48(); #elif HAVE_RAND_R static unsigned int seed = time(NULL); result = rand_r(&seed); #elif HAVE_RAND static FcBool initialized = FcFalse; if (initialized != FcTrue) { srand(time(NULL)); initialized = FcTrue; } result = rand(); #else # error no random number generator function available. #endif return result; }
static model_t*perceptron_train(perceptron_model_factory_t*factory, dataset_t*d) { int num_iterations = d->num_rows*100; double base_eta = 0.1; double lastperf = 1.0; double currentperf = -1; int t; double*weights = calloc(sizeof(double), d->num_columns); if(dataset_has_categorical_columns(d)) return NULL; if(d->desired_response->num_classes > 2) return NULL; double class_to_level[2] = {-1, 1}; for(t=1;t<num_iterations;t++) { int i = lrand48() % d->num_rows; double eta = base_eta / t; if(predict(d, weights, i) != d->desired_response->entries[i].c) { update_weights(weights, d, i, eta); } } expanded_columns_t*expanded_columns = expanded_columns_new(d); START_CODE(program) BLOCK IF LT ADD for(t=0;t<d->num_columns;t++) { MUL INSERT_NODE(expanded_columns_parameter_code(expanded_columns, t)) FLOAT_CONSTANT(weights[t]) END; } END; FLOAT_CONSTANT(0.0); END; THEN GENERIC_CONSTANT(d->desired_response->classes[0]); ELSE GENERIC_CONSTANT(d->desired_response->classes[1]); END; END_CODE; expanded_columns_destroy(expanded_columns); model_t*m = model_new(d); m->code = program; return m; }
void permute(cuex_t *arr, size_t cnt) { size_t i; for (i = 1; i < cnt; ++i) { size_t j = lrand48() % (i + 1); cuex_t save = arr[i]; arr[i] = arr[j]; arr[j] = save; } }
void sampleHWt(ZZX &poly, long Hwt, long n) { if (n<=0) n=deg(poly)+1; if (n<=0) return; clear(poly); // initialize to zero poly.SetMaxLength(n); // allocate space for degree-(n-1) polynomial long b,u,i=0; if (Hwt>n) Hwt=n; while (i<Hwt) { // continue until exactly Hwt nonzero coefficients u=lrand48()%n; // The next coefficient to choose if (IsZero(coeff(poly,u))) { // if we didn't choose it already b = lrand48()&2; // b random in {0,2} b--; // random in {-1,1} SetCoeff(poly,u,b); i++; // count another nonzero coefficient } } poly.normalize(); // need to call this after we work on the coeffs }
void Model::shuffle(){ int n = CARD_COUNT; while ( n > 1 ) { int k = (int) (lrand48() % n); --n; Card *c = cards_[n]; cards_[n] = cards_[k]; cards_[k] = c; } }