void STGM::CBoolSphereSystem::simSphereSys(R_Calldata d) { GetRNGstate(); if(isNull(d->call)) { /* get arguments */ double p1=REAL_ARG_LIST(d->args,0),p2=0; const char *fname = CHAR(STRING_ELT(d->fname,0)); /* ACHTUNG: 'const' function braucht 2 Argumente */ if(std::strcmp(fname, "const" )) p2=REAL_ARG_LIST(d->args,1); // set spheroid label const char *label = translateChar(asChar(d->label)); if(!std::strcmp(fname, "rlnorm")) { simSpheresPerfect(p1,p2,label,d->isPerfect); } else { R_rndGen_t<rdist2_t> rrandom(p1,p2,fname); /* simulate with R's random generating functions */ simSpheres<R_rndGen_t<rdist2_t> >(rrandom,label); } } else { /* eval R call for user defined radii distribution */ const char *label = translateChar(asChar(d->label)); R_eval_t<double> reval(d->call, d->rho); simSpheres<R_eval_t<double> &>(reval,label); } PutRNGstate(); }
int luaopen_irccmd_internal(lua_State *L) { #if _DEBUG compare_Test(); fprintf(stderr, "Tests completed\n"); #endif frandom_init(&frand, rrandom()); luaL_Reg array[] = { { "random", &luafunc_random }, { "frandom", &luafunc_frandom }, { "milliseconds", &luafunc_milliseconds }, { "milliseconds_diff", &luafunc_milliseconds_diff }, { "console_print", &luafunc_console_print }, { "console_print_err", &luafunc_console_print_err }, { "irc_input", &luafunc_irc_input }, { "irc_parse", &luafunc_irc_parse }, { "compare_ascii", &luafunc_compare_ascii }, { "compare_rfc1459", &luafunc_compare_rfc1459 }, { "compare_strict_rfc1459", &luafunc_compare_rfc1459 }, { "tolower_ascii", &luafunc_tolower_ascii }, { "tolower_rfc1459", &luafunc_tolower_rfc1459 }, { "tolower_strict_rfc1459", &luafunc_tolower_strict_rfc1459 }, { "socket_connect", &luafunc_socket_connect }, { "socket_bind", &luafunc_socket_bind }, { "socket_listen", &luafunc_socket_listen }, { "socket_accept", &luafunc_socket_accept }, { "socket_close", &luafunc_socket_close }, { "socket_blocking", &luafunc_socket_blocking }, { "socket_linger", &luafunc_socket_linger }, /* { "socket_reuseaddr", &luafunc_socket_reuseaddr }, */ { "socket_shutdown", &luafunc_socket_shutdown }, { "socket_send", &luafunc_socket_send }, { "socket_receive", &luafunc_socket_receive }, { "socket_select", &luafunc_socket_select }, { "memory_limit", &luafunc_memory_limit }, #ifdef HAS_UTF32toUTF8char { "UTF32toUTF8char", &luafunc_UTF32toUTF8char }, #endif { "socket_startup", &luafunc_socket_startup }, { "socket_cleanup", &luafunc_socket_cleanup }, { NULL, NULL } }; luaL_register(L, "internal", array); /* Deprecated global */ return 1; }
/** x = random([limit]) */ static int luafunc_random(lua_State *L) { unsigned long rn = rrandom(); if(lua_isnumber(L, 1)) { unsigned long limit = (unsigned long)lua_tonumber(L, 1); if(limit > 0) { rn %= limit; } else { _programError("luafunc_random limit cannot be 0", 0); return 0; } } lua_pushnumber(L, rn); return 1; /* Number of return values. */ }
/** * Partitions data in [start, end) using a randomly chosen pivot value. * All data before the returned location is lte the pivot, and all data * after is gt the value. */ int* partition(int *start, int *end) { // pick a random pivot value, move it to the end of the array exchange(start + rrandom(0, end - start), end - 1); // this is the last element lte the pivot int *boundary = start - 1; for (int *comp = start; comp < end - 1; ++comp) { // loop through all the elements from the beginning to the element just // before the pivot if (*comp <= end[-1]) { // if the value is lte the pivot, increase the boundary by one and // swap the value with the lte one ++boundary; exchange(boundary, comp); } } // move the pivot in place ++boundary; exchange(boundary, end - 1); return boundary; }
void RandomCoord() { for(std::size_t i = 0 ; i < dim_type ; i++) coord[i] = rrandom(); }