/* * load disc; */ int audiocd_tray_load(char driveid) { HANDLE hdrive; unsigned long nbr = 0; unsigned int realindex; int res; if(!engine_initialized)audiocd_initialize(); if(driveid < 'A' || driveid > 'Z')return -2; /* error: invalid drive id */ /* real index: 0 to 25 */ realindex = driveid - 'A'; if(loaded_drives[realindex].drive) { hdrive = loaded_drives[realindex].drive; } else { letter windows_path[8] = {uni('\\'), uni('\\'), uni('.'), uni('\\'), (letter)driveid, uni(':'), uni('\0')}; hdrive = CreateFile(windows_path, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); if(hdrive == INVALID_HANDLE_VALUE)return -2; /* error: cannot load driver 'driveid' */ } res = DeviceIoControl(hdrive, IOCTL_STORAGE_LOAD_MEDIA, 0, 0, 0, 0, &nbr, 0); if(!loaded_drives[realindex].drive) { CloseHandle(hdrive); } return (!res); }
void PertyRemoveTagVisitor::visit(const shared_ptr<Element>& e) { boost::uniform_real<> uni(0.0, 1.0); Tags t = e->getTags(); for (Tags::const_iterator it = t.constBegin(); it != t.constEnd(); ++it) { const QString tagKey = it.key(); if (uni(*_rng) <= _p && !_exemptTagKeys.contains(tagKey)) { if (!_replacementTagKeys.contains(tagKey)) { LOG_DEBUG("Removing tag with key: " << tagKey << " ..."); e->getTags().remove(tagKey); } else { const int tagIndex = _replacementTagKeys.indexOf(tagKey); const QString tagValue = _replacementTagValues.at(tagIndex); LOG_DEBUG("Substituting value: " << tagValue << " for tag with key: " << tagKey); e->getTags().set(tagKey, tagValue); } } } }
int DiceRoller::diceRoll(int type) { assert(m_allowedDice.find(type) != m_allowedDice.end()); std::uniform_int_distribution<int> uni(1, type); return uni(m_rng); }
void solve(){ int i,j,x; for(i=1;i<=n;++i){f[i]=i-1;used[i]=false;} for(i=0;i<m;++i){ if(used[p[i]]){ x=find(p[i]); use(x+1,i+1); uni(x,x+1); if(used[x+2])uni(x+1,x+2); }else{ use(p[i],i+1); uni(p[i],p[i]+1); if(used[p[i]-1])uni(p[i]-1,p[i]); } } inittree(); memset(r,0,sizeof(r)); for(i=n;i>0;--i){ if(used[i]){ for(j=head[find(i)];j;j=next[j]) r[remove(p[j-1])]=j; while(used[i] && i)--i; } } for(i=n;i;--i)if(r[i])break; printf("%d\n",i); for(j=1;j<=i;++j){ if(j>1)printf(" "); printf("%d",r[j]); } printf("\n"); }
unsigned int fileassociation_geticonid(const string ext) { letter apext[255]; letter apcls[255]; letter rvalue[260]; unsigned long rvsize = sizeof(rvalue); const string cls_name = uni("fennec.player.file."); int iconid = 0; string pt; apext[0] = uni('.'); str_cpy(apext + 1, ext); str_cpy(apcls, cls_name); str_cat(apcls, ext); /* i.e. "fennec.player.file.ogg" */ str_cat(apcls, uni("\\DefaultIcon")); if(RegQueryValue(HKEY_CLASSES_ROOT, apcls, rvalue, (PLONG)&rvsize) != ERROR_SUCCESS) goto pt_retdefaultid; if(!rvsize) goto pt_retdefaultid; pt = str_rchr(rvalue, uni(',')); if(!pt) goto pt_retdefaultid; pt++; /* ',' */ while(*pt == uni(' '))pt++; iconid = str_stoi(pt); return iconid; pt_retdefaultid: /* default icon ids */ return get_default_file_icon(ext); }
float random_float(float min, float max) { random_device rd; mt19937 rng(rd()); uniform_real_distribution<float> uni(min,max); return uni(rng); }
int random_int(int min, int max) { random_device rd; mt19937 rng(rd()); uniform_int_distribution<int> uni(min,max); return uni(rng); }
void runBasicTest() { shared_ptr<OsmMap> map(new OsmMap()); OGREnvelope env; env.MinX = 0; env.MinY = 0; env.MaxX = 1; env.MaxY = 1; map->setProjection(MapReprojector::createAeacProjection(env)); boost::minstd_rand rng(1); boost::uniform_real<> uni(0.0, 1000.0); for (int i = 0; i < 100; i++) { NodePtr n(new Node(Status::Unknown1, map->createNextNodeId(), uni(rng), uni(rng), 10)); map->addNode(n); } PertyRemoveRandomElementVisitor v; v.setRng(rng); map->visitRw(v); CPPUNIT_ASSERT_EQUAL(96, (int)map->getNodeMap().size()); }
float perform_random_point_queries (SpatialIndex::ISpatialIndex * tree, const SpatialIndex::Region & query_region, const unsigned number_of_queries) { boost::mt11213b generator (42u); const double x[3] = {0.0, 0.0, 0.0}; access_count_visitor v; for (unsigned j = 0; j < number_of_queries; j++) { SpatialIndex::Point rnd_point (x, query_region.m_dimension); for (size_t i = 0; i < query_region.m_dimension; i++) { boost::uniform_real<> uni_dist (query_region.m_pLow[i], query_region.m_pHigh[i]); boost::variate_generator<boost::mt11213b &, boost::uniform_real<> > uni(generator, uni_dist); rnd_point.m_pCoords[i] = uni(); } assert (query_region.containsPoint (rnd_point)); v.new_query(); tree->pointLocationQuery (rnd_point, v); } v.print_stats(); return v.get_avg_io(); }
uint GetRandom(uint min, uint max) { std::random_device rd; std::mt19937 rng(rd()); std::uniform_int_distribution<uint> uni(min, max); return uni(rng); }
double HG_Random::get_random_01_value() { // Define a uniform random number distribution which produces "double" // values between 0 and 1 (0 inclusive, 1 exclusive). boost::uniform_real<> uni_dist(0,1); boost::variate_generator<HG_RandomGenerator_t&, boost::uniform_real<> > uni(HG_Random::random_generator, uni_dist); return uni(); }
int main(){ //ROOT::Cintex::Cintex::Enable(); pool::POOLContext::loadComponent( "SEAL/Services/MessageService" ); pool::POOLContext::loadComponent("COND/Services/TBufferBlobStreamingService"); pool::POOLContext::setMessageVerbosityLevel( seal::Msg::Error ); pool::Placement place; place.setDatabase("sqlite_file:strip.db", pool::DatabaseSpecification::PFN ); place.setContainerName("mySiStripNoisesRcd"); place.setTechnology(pool::POOL_RDBMS_HOMOGENEOUS_StorageType.type()); pool::IFileCatalog* fileCatalog = new pool::IFileCatalog; fileCatalog->setWriteCatalog( "file:me.xml" ); fileCatalog->connect(); fileCatalog->start(); pool::IDataSvc* datasvc = pool::DataSvcFactory::instance( fileCatalog ); pool::DatabaseConnectionPolicy policy; policy.setWriteModeForNonExisting( pool::DatabaseConnectionPolicy::CREATE ); policy.setWriteModeForExisting( pool::DatabaseConnectionPolicy::OVERWRITE); datasvc->session().setDefaultConnectionPolicy( policy ); datasvc->transaction().start(pool::ITransaction::UPDATE); mySiStripNoises* myobj = new mySiStripNoises; unsigned int detidseed=1234; unsigned int bsize=100; unsigned int nAPV=2; base_generator_type rng(42u); boost::uniform_real<> uni_dist(0,1); boost::variate_generator<base_generator_type&, boost::uniform_real<> > uni(rng, uni_dist); for(unsigned int detid=detidseed; detid<(detidseed+bsize);detid++){ std::vector<short> theSiStripVector; for(unsigned int strip=0; strip<128*nAPV; ++strip){ std::cout<<strip<<std::endl; float noise = uni();; myobj->setData(noise,theSiStripVector); } myobj->put(detid,theSiStripVector); } std::cout<<"about to build ref"<<std::endl; pool::Ref< mySiStripNoises > simple(datasvc,myobj); std::cout<<"about to mark write"<<std::endl; simple.markWrite(place); std::cout<<"about to commit"<<std::endl; std::string t=simple.toString(); std::cout<<"token "<<t<<std::endl; datasvc->transaction().commit(); std::cout<<"committed"<<std::endl; datasvc->transaction().start(pool::ITransaction::READ); std::cout<<"about to read back"<<std::endl; pool::Ref< mySiStripNoises > p(datasvc,t); unsigned int a=p->v_noises.size(); std::cout<<"size a "<<a<<std::endl; unsigned int b=p->indexes.size(); std::cout<<"size b "<<b<<std::endl; datasvc->transaction().commit(); datasvc->session().disconnectAll(); fileCatalog->commit(); fileCatalog->disconnect(); return 0; }
void PertyRemoveRandomElementVisitor::visit(const ConstElementPtr& e) { boost::uniform_real<> uni(0.0, 1.0); if (uni(*_rng) <= _p) { RecursiveElementRemover(ElementId(e->getElementType(), e->getId())).apply(_map->shared_from_this()); } }
int callc encoder_about(unsigned long id, void* odata) { #if defined(system_microsoft_windows) MessageBox((HWND)odata, uni("Advanced Audio Codec (encoder) 1.0 for Fennec"), uni("Advanced Audio Codec"), MB_ICONINFORMATION); #endif return 1; }
void typo_create_fonts(void) { typo_fonts[typo_song_title] = typo_makefont(uni("Verdana"), 18, 1, 0); typo_fonts[typo_song_artist] = typo_makefont(uni("Verdana"), 12, 1, 0); typo_fonts[typo_song_album] = typo_makefont(uni("Verdana"), 12, 0, 1); typo_fonts[typo_song_position] = typo_makefont(uni("Verdana"), 12, 1, 0); }
/*---------------------------------------------------------------------------*\ | SixStepTemplateMethod base class methods \*---------------------------------------------------------------------------*/ SixStepTemplateMethod::SixStepTemplateMethod( const char* name = "" ) : m_implementation_name( name ) { std::random_device rd; std::uniform_int_distribution<int> uni( 0, 23 ); auto random_hour = uni( rd ); m_morning = ( random_hour < 12 ); }
/* * show 'settings' dialog etc. */ int callc fennec_plugin_settings(void* pdata) { # if defined(system_microsoft_windows) MessageBox((HWND)pdata, uni("There's nothing to configure."), uni("REX Decoder Settings"), MB_ICONINFORMATION); # endif return 1; }
/* * show some information. * 'fennec_invalid_index' to display general about. */ int callc encoder_about(unsigned long id, void* odata) { # if defined(system_microsoft_windows) MessageBox((HWND)odata, uni("Sample Codec for Fennec Player."), uni("About Sample Codec"), MB_ICONINFORMATION); # endif return 1; }
/* * show 'about plugin' dialog etc. */ int callc fennec_plugin_about(void* pdata) { # if defined(system_microsoft_windows) MessageBox((HWND)pdata, uni("REX Decoder for Fennec Player."), uni("About REX Decoder"), MB_ICONINFORMATION); # endif return 1; }
void test_generate_symbols() { //size_t totalLen = 800; size_t lineLen = 60; size_t wordLen = 8; char letters[] = {'q', 'w', 'e', 'r', 't', 'y','u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm' }; char upperLetters[] = {'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M' }; size_t lettersCount = 26; char symbols[] = {';', ','}; size_t symbolsCount = 2; size_t upperLettersFreq = 6; // frequancy of appearance of the upper letter size_t symbolsFreq = 4; // frequancy of appearance of the upper letter std::random_device rd; // only used once to initialise (seed) engine std::mt19937 rng(rd()); // random-number engine used (Mersenne-Twister in this case) std::uniform_int_distribution<size_t> uni(0, lettersCount-1); // guaranteed unbiased std::uniform_int_distribution<size_t> upperFreqRandom(0, upperLettersFreq-1); // guaranteed unbiased std::uniform_int_distribution<size_t> symbolsFreqRandom(0, symbolsFreq-1); // std::uniform_int_distribution<size_t> symbolsRandom(0, symbolsCount-1); // guaranteed unbiased std::uniform_int_distribution<size_t> wordLenRandom(4, 8); // guaranteed unbiased //std::default_random_engine generator; //std::normal_distribution<double> distribution(0.0, 0.1); SplitterInfo spInfo= {false, false, 0, 0, wordLen, lineLen, wordLen, 0}; //size_t charIndex = 0; size_t totalLines = 10; //size_t linesCount = 0; while (spInfo.linesCount < totalLines) { size_t lettersIndex = uni(rng); if (upperFreqRandom(rng)==0) { size_t uLetterIndex = uni(rng); std::cout << upperLetters[uLetterIndex]; spInfo.newWordLen = wordLenRandom(rng); printSplitters(spInfo); } if (symbolsFreqRandom(rng)==0) { size_t symbolsIndex = symbolsRandom(rng); std::cout << symbols[symbolsIndex]; spInfo.newWordLen = wordLenRandom(rng); printSplitters(spInfo); } std::cout<<letters[lettersIndex]; spInfo.newWordLen = wordLenRandom(rng); printSplitters(spInfo); } std::cout << std::endl; // end of line }
int callc about(unsigned long id, void* odata) { #if defined(system_microsoft_windows) MessageBox((HWND)odata, uni("Lame audio encoder 3.97\nhttp://www.mp3dev.org"), uni("About LAME"), MB_ICONINFORMATION); #endif return 1; }
int randint(int min, int max) { if (!init_rand) { device.seed(time(0)); init_rand = true; } if (min>max) return 0; std::uniform_int_distribution<int> uni(min, max); return uni(device); }
// Make a random box inside the World Box with the given percentage Volume void Box::randomBox(const Box& world, const float percentageVolume,Box& random) { bigSpaceUnit newVolume = volume(world)*percentageVolume/100; spaceUnit dimensionInc = pow(newVolume,1.0/3.0) /2; for (size_t i = 0; i < DIMENSION; i++) { boost::uniform_real<> uni_dist (world.low.Vector[i],world.high.Vector[i]); boost::variate_generator<boost::mt11213b &,boost::uniform_real<> > uni(generator, uni_dist); float center = uni(); random.low.Vector[i] = center-dimensionInc; random.high.Vector[i] = center+dimensionInc; } }
int main() { // Handle CTLR + C struct sigaction sigIntHandler; sigIntHandler.sa_handler = handleSignal; sigemptyset(&sigIntHandler.sa_mask); sigaction(SIGINT, &sigIntHandler, NULL); quit = false; auto lead = new car("lead"); auto follower = new car("follower"); auto controller = new pidController(); follower->setSpeed(0); lead->setSpeed(0); controller->setSetPoint(lead->getSpeed()); controller->setKi(1); controller->setKd(1); controller->setKp(.2); auto pvThread = std::thread(runPv, controller); auto pidThread = std::thread(runPid, controller); auto simThread = std::thread(runSim, lead, follower, controller); std::random_device rd; // only used once to initialise (seed) engine std::mt19937 rng(rd()); // random-number engine used (Mersenne-Twister in this case) std::uniform_int_distribution<int> uni(0,4); // guaranteed unbiased while (!quit) { int randomSpeed = uni(rng); lead->setSpeed(randomSpeed); controller->setSetPoint(lead->getSpeed()); sleepSim(2); } pvThread.join(); simThread.join(); pidThread.join(); delete lead; delete follower; delete controller; return 0; }
int encoder_appendextension(unsigned long id, string fpath) { int v = 0; if(fsettings.plugin_settings_getnum("aac", "mp4", &v, 0, 0))v = 0; pestreams[id].ismp4 = v; if(pestreams[id].ismp4) str_cat(pestreams[id].filepath, uni(".mp4")); else str_cat(pestreams[id].filepath, uni(".aac")); return 1; }
int main(){ int t,n,m,i,j,a,b,flag; scanf("%d",&t); for(j=1;j<=t;j++){ memset(bug,0,sizeof(bug)); scanf("%d%d",&n,&m); for(flag=i=0;i<m;i++){ scanf("%d%d",&a,&b); uni(a,b+n),uni(b,a+n); if(fin(a)==fin(a+n)||fin(b)==fin(b+n)) flag=1; } printf("Scenario #%d:\n",j); puts(flag?"Suspicious bugs found!\n":"No suspicious bugs found!\n"); } }
int callc fennec_visualization_initialize(struct general_visualization_data *sdata, string plgtitle) { memcpy(&sfennec, sdata->shared, sizeof(struct fennec)); memcpy(&visdata, sdata, sizeof(struct general_visualization_data)); sdata->uninitialize = visualization_uninitialize; sdata->refresh = visualization_refresh; sdata->settings = visualization_settings; sdata->about = visualization_about; sdata->fsettings.plugin_settings_getnum("vis.spectrum", "intense", &intensecolors, 0, 0); sdata->fsettings.plugin_settings_getnum("vis.spectrum", "showfall", &showfall, 0, 0); sdata->fsettings.plugin_settings_getnum("vis.spectrum", "showbars", &showbars, 0, 0); sdata->fsettings.plugin_settings_getnum("vis.spectrum", "fallco", &fallco, 0, 0); sdata->fsettings.plugin_settings_getnum("vis.spectrum", "barscount", &bars_count, 0, 0); str_cpy(plgtitle, uni("Spectrum Analyzer")); visdata.getdata(get_visual_dc, 0, &dc, 0); visdata.getdata(set_msg_proc, 0, vis_message, 0); visdata.getdata(get_visual, 0, &window_vis, 0); vwx = visdata.getdata(get_visual_x, 0, 0, 0); vwy = visdata.getdata(get_visual_y, 0, 0, 0); vww = visdata.getdata(get_visual_w, 0, 0, 0); vwh = visdata.getdata(get_visual_h, 0, 0, 0); draw_rect(vwx, vwy, vww, vwh, 0); timer_id = SetTimer(0, 0, 30, timer_display); col_bar_line = color_adjust(visdata.getdata(get_color, color_dark, 0, 0), 0.3); col_bar_fill = (COLORREF)visdata.getdata(get_color, color_dark, 0, 0); return 1; }
void init() { std::random_device rd; std::mt19937 rng(rd()); std::uniform_real_distribution<double> uni(0, 1); random_percentage = std::bind(uni, rng); }
void OutputPatch_Test::dump() { QByteArray uni(513, char(0)); uni[0] = 100; uni[169] = 50; uni[511] = 25; OutputMap om(m_doc, 4); OutputPatch* op = new OutputPatch(this); OutputPluginStub* stub = static_cast<OutputPluginStub*> (m_doc->ioPluginCache()->plugins().at(0)); QVERIFY(stub != NULL); op->set(stub, 0); QVERIFY(stub->m_universe[0] == (char) 0); QVERIFY(stub->m_universe[169] == (char) 0); QVERIFY(stub->m_universe[511] == (char) 0); op->dump(uni); QVERIFY(stub->m_universe[0] == (char) 100); QVERIFY(stub->m_universe[169] == (char) 50); QVERIFY(stub->m_universe[511] == (char) 25); delete op; }
void kruskal() { int* parent = (int*)malloc(sizeof(int)*nrOfVerteces); int i, trees = nrOfVerteces, nrEdges = 0; for(i=0; i<nrOfVerteces; i++) parent[i] = i; edgeT minEdge; edgeT *edges = (edgeT*) malloc(sizeof(edgeT)*(nrOfVerteces-1)); int** copyOfAdjMatrix = getCopyOfAdjecencyMatrix(adjMatrix); while(trees > 1) { minEdge = getMinimumEdgeForAdjacencyMatrix(copyOfAdjMatrix); removeEdge(copyOfAdjMatrix, minEdge); if(uni(parent, minEdge.source, minEdge.destination) != 0) { trees--; edges[nrEdges] = minEdge; nrEdges++; } } printf("\nKruskal:\n"); printEdges(edges, nrOfVerteces-1); printf("\n"); }