void expected_state_test() { auto x = State(model.state_dimension()); auto u = Input(model.input_dimension()); x.setRandom(); u.setRandom(); EXPECT_TRUE( fl::are_similar( model.expected_state(x, u), x + model.input_matrix() * u)); }
void state_test() { auto x = State(model.state_dimension()); auto u = Input(model.input_dimension()); auto w = Noise(model.noise_dimension()); x.setRandom(); u.setRandom(); w.setRandom(); EXPECT_TRUE( fl::are_similar( model.state(x, w, u), x + model.input_matrix() * u + w)); }
// // Called from AppleKeyPairGenContext // void BSafe::BSafeKeyPairGenContext::generate( const Context &context, BinaryKey &pubBinKey, // valid on successful return BinaryKey &privBinKey, // ditto uint32 &keySize) // ditto { /* these casts throw exceptions if the keys are of the * wrong classes, which is a major bogon, since we created * the keys in the above generate() function */ BSafeBinaryKey &bsPubBinKey = dynamic_cast<BSafeBinaryKey &>(pubBinKey); BSafeBinaryKey &bsPrivBinKey = dynamic_cast<BSafeBinaryKey &>(privBinKey); if (!initialized) { setupAlgorithm(context, keySize); check(B_GenerateInit(bsAlgorithm, chooser(), bsSurrender), true); initialized = true; } setRandom(); check(B_GenerateKeypair(bsAlgorithm, bsPubBinKey.bsKey(), bsPrivBinKey.bsKey(), bsRandom, bsSurrender), true); }
std::shared_ptr<ir::Expr> LoadRealMatrixFuncDecl::getNew( std::vector<std::shared_ptr<ir::Expr>>& args, fabrica::TypeFactory* fact) const { // Type Checking auto mat_ty = fact->getTy(ir::IRConstString::MATRIX); auto int_ty = fact->getTy(ir::IRConstString::INT); auto str_ty = fact->getTy(ir::IRConstString::STRING); if (args.size() < 1 || args[0] == nullptr || args[0]->getTyp() != str_ty) return nullptr; for (size_t i = 1; i < args.size(); ++i) { if (args[i] == nullptr || args[i]->getTyp() != int_ty) return nullptr; } if (args.size() > 5) return nullptr; if (args.size() == 4) return nullptr; auto func = std::make_shared<ir::FunctionCall>(this); func->setArgs(args); // check randomness for (auto& a : args) { if (a->isRandom()) func->setRandom(true); } func->setTyp(mat_ty); return func; }
void noise_matrix_value_test() { auto noise_matrix = model.create_noise_matrix(); noise_matrix.setRandom(); model.noise_matrix(noise_matrix); EXPECT_TRUE(fl::are_similar(model.noise_matrix(), noise_matrix)); }
Map::Map() { // Get seed for noise setRandom(1); // Initiate point-map this->chunkSize = pow(2, 5) + 1;// +1 gives the map a mid-point seed = 60.0f; ds = new float*[chunkSize];// 33x33, 17x17, etc for (int i = 0; i < chunkSize; i++) { ds[i] = new float[chunkSize]; } chunkSize--; // Initiate map tiles = new TileClass*[chunkSize];// 32x32, 16x16, etc baseTiles = new BaseTile*[chunkSize]; for (int i = 0; i < chunkSize; i++) { tiles[i] = new TileClass[chunkSize]; baseTiles[i] = new BaseTile[chunkSize]; } // Create noise - algorithm usage DiamondSquare(30.0f, 0.76789f); // Create Tile-based map CreateTiles(); }
PlaylistModel::PlaylistModel(QObject* parent): QAbstractListModel(parent), d(new Private) { KConfigGroup cfgGroup = KGlobal::config()->group("General"); setRandom(cfgGroup.readEntry("randomplaylist",false)); QString dirPath = KGlobal::dirs()->saveLocation("data") + KCmdLineArgs::appName(); QDir().mkdir(dirPath); d->filePath = dirPath + "/playlist"; if (QFile::exists(d->filePath)) { QFile file(d->filePath); if (file.open(QIODevice::ReadOnly)) { QTextStream in(&file); while (!in.atEnd()) { QString line = in.readLine(); d->musicList.append(PlaylistItem::fromString(line)); } } file.close(); } d->currentIndex = -1; setRoleNames(MediaCenter::appendAdditionalMediaRoles(roleNames())); qsrand(QDateTime::currentMSecsSinceEpoch()); }
std::shared_ptr<ir::Expr> MathFuncDecl::getNew( std::vector<std::shared_ptr<ir::Expr>>& args, fabrica::TypeFactory* fact) const { // Type Checking if (args.size() != 1 || args[0] == nullptr) return nullptr; auto int_ty = fact->getTy(ir::IRConstString::INT); auto real_ty = fact->getTy(ir::IRConstString::DOUBLE); auto mat_ty = fact->getTy(ir::IRConstString::MATRIX); // Note: We accept Int/Real/Matrix if (args[0]->getTyp() != int_ty && args[0]->getTyp() != real_ty && args[0]->getTyp() != mat_ty) return nullptr; auto ret_ty = (args[0]->getTyp() == mat_ty ? mat_ty : real_ty); auto func = std::make_shared<ir::FunctionCall>(this); func->addArg(args[0]); // check randomness func->setRandom(func->get(0)->isRandom()); func->setTyp(ret_ty); return func; }
HttpRequestHandler::HandleStatus StatusApi::handle(HttpRequest *request, HttpResponse *response) { if (HttpRequest::Method_Get==request->method()) { if (request->path()=="/api/v1/status/socket") { response->write("{\"port\":"+QByteArray::number(serverPort())+"}"); return Status_Handled; } else if (request->path()=="/api/v1/status") { response->write(statusMessage()); return Status_Handled; } else if (request->path()=="/api/v1/status/current") { response->write(currentSongMessage()); return Status_Handled; } } else if(HttpRequest::Method_Post==request->method() && request->path()=="/api/v1/status") { QString repeat=request->parameter("repeat"); QString random=request->parameter("random"); QString single=request->parameter("single"); QString consume=request->parameter("consume"); DBUG << repeat << random << single << consume; if (!repeat.isEmpty()) { emit setRepeat(isSet(repeat)); } if (!random.isEmpty()) { emit setRandom(isSet(random)); } if (!single.isEmpty()) { emit setSingle(isSet(single)); } if (!consume.isEmpty()) { emit setConsume(isSet(consume)); } return Status_Handled; } return Status_BadRequest; }
void sensor_matrix_value_test() { auto sensor_matrix = model.create_sensor_matrix(); sensor_matrix.setRandom(); model.sensor_matrix(sensor_matrix); EXPECT_TRUE(fl::are_similar(model.sensor_matrix(), sensor_matrix)); }
Map::Map(int randSeed, int exponent, float startValue) { // Get seed for noise setRandom(randSeed); // Initiate point-map this->chunkSize = pow(2, exponent) + 1;// +1 gives the map a mid-point seed = startValue; ds = new float*[chunkSize];// 33x33, 17x17, etc for (int i = 0; i < chunkSize; i++) { ds[i] = new float[chunkSize]; } chunkSize--; // Initiate map tiles = new TileClass*[chunkSize];// 32x32, 16x16, etc baseTiles = new BaseTile*[chunkSize]; for (int i = 0; i < chunkSize; i++) { tiles[i] = new TileClass[chunkSize]; baseTiles[i] = new BaseTile[chunkSize]; } // Create noise - algorithm usage DiamondSquare((startValue * 0.5f), 0.76789f); // Create Tile-based map CreateTiles(); }
void dynamics_matrix_value_test() { auto dynamics_matrix = model.dynamics_matrix(); dynamics_matrix.setRandom(); model.dynamics_matrix(dynamics_matrix); EXPECT_TRUE(fl::are_similar(model.dynamics_matrix(), dynamics_matrix)); }
/* This function configure the initial state of the player * MPD keep its own internal state, so we have to reset it */ void Player::configureInitial() { stop(); setRepeat(false); setRandom(false); removeAllTracks(); }
void observation_test() { auto x = State(model.state_dimension()); auto y = Obsrv(model.obsrv_dimension()); auto v = Noise(model.noise_dimension()); x.setRandom(); v.setRandom(); auto H = model.create_sensor_matrix(); H.setIdentity(); y = H * x; y += v; EXPECT_TRUE(fl::are_similar(model.observation(x, v), y)); }
void setRandom(struct RandomListNode* head){ if(!head){ return; } if(head->random){ head->next->random = head->random->next; } setRandom(head->next->next); }
struct RandomListNode *copyRandomList(struct RandomListNode *head) { if(!head){ return head; } appendNew(head); setRandom(head); struct RandomListNode* ans = head->next; restore(head); return ans; }
int _tmain() { setlocale(LC_ALL,"rus"); srand(time(NULL)); setTable(tableHuman); setTable(tableCpu); setRandom(tableCpu,4); setRandom(tableCpu,3); setRandom(tableCpu,3); setRandom(tableCpu,2); setRandom(tableCpu,2); setRandom(tableCpu,2); setRandom(tableCpu,1); setRandom(tableCpu,1); setRandom(tableCpu,1); setRandom(tableCpu,1); printTable(tableHuman,0,0); printTable(tableCpu,15,0); movesOnTable(); _gettch(); return 0; }
void expected_observation_test() { auto x = State(model.state_dimension()); auto y = Obsrv(model.obsrv_dimension()); x.setRandom(); y.setZero(); auto H = model.create_sensor_matrix(); H.setIdentity(); y = H * x; EXPECT_TRUE(fl::are_similar(model.expected_observation(x), y)); }
// // DSA Parameter Generation // void BSafe::BSafeKeyPairGenContext::generate( const Context &context, uint32 bitSize, CssmData ¶ms, uint32 &attrCount, Context::Attr * &attrs) { assert(context.algorithm() == CSSM_ALGID_DSA); B_ALGORITHM_OBJ genAlg = NULL; B_ALGORITHM_OBJ result = NULL; try { check(B_CreateAlgorithmObject(&genAlg)); B_DSA_PARAM_GEN_PARAMS genParams; genParams.primeBits = bitSize; check(B_SetAlgorithmInfo(genAlg, AI_DSAParamGen, POINTER(&genParams))); setRandom(); check(B_GenerateInit(genAlg, chooser(), bsSurrender), true); check(B_CreateAlgorithmObject(&result)); check(B_GenerateParameters(genAlg, result, bsRandom, bsSurrender)); // get parameters out of algorithm object A_DSA_PARAMS *kParams = NULL; check(B_GetAlgorithmInfo((POINTER *)&kParams, result, AI_DSAKeyGen), true); // shred them into context attribute form attrs = normAllocator->alloc<Context::Attr>(3); attrs[0] = Context::Attr(CSSM_ATTRIBUTE_PRIME, *BSafeItem(kParams->prime).copyp<CssmData>(*normAllocator)); attrs[1] = Context::Attr(CSSM_ATTRIBUTE_SUBPRIME, *BSafeItem(kParams->subPrime).copyp<CssmData>(*normAllocator)); attrs[2] = Context::Attr(CSSM_ATTRIBUTE_BASE, *BSafeItem(kParams->base).copyp<CssmData>(*normAllocator)); attrCount = 3; // clean up B_DestroyAlgorithmObject(&result); B_DestroyAlgorithmObject(&genAlg); } catch (...) { // clean up B_DestroyAlgorithmObject(&result); B_DestroyAlgorithmObject(&genAlg); throw; } }
int PlaylistModel::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QAbstractListModel::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 8) qt_static_metacall(this, _c, _id, _a); _id -= 8; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< int*>(_v) = currentIndex(); break; case 1: *reinterpret_cast< bool*>(_v) = random(); break; } _id -= 2; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setCurrentIndex(*reinterpret_cast< int*>(_v)); break; case 1: setRandom(*reinterpret_cast< bool*>(_v)); break; } _id -= 2; } else if (_c == QMetaObject::ResetProperty) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 2; } #endif // QT_NO_PROPERTIES return _id; }
std::shared_ptr<ir::Expr> DiscreteDistrDecl::getNew( std::vector<std::shared_ptr<ir::Expr>>& args, fabrica::TypeFactory* fact) const { // Type Checking if (args.size() != 1 || args[0] == nullptr) return nullptr; // Note: We only accept array<double> auto dbl = fact->getTy(ir::IRConstString::DOUBLE); auto ary_dbl = fact->getUpdateTy(new ir::ArrayTy(dbl, 1)); auto mtrx = fact->getTy(ir::IRConstString::MATRIX); if (args[0]->getTyp() != ary_dbl && args[0]->getTyp() != mtrx) return nullptr; auto ret = std::make_shared<ir::Distribution>(this->getName(), this); ret->setArgs(args); ret->setTyp(fact->getTy(ir::IRConstString::INT)); ret->processArgRandomness(); ret->setRandom(true); return ret; }
void MazeInit(int argc, char **argv) { getMaze(); setRandom(); InitDisplay(argc, argv); NewPosition(M); printf("%d X LOC \n",M->xloc().value()); /* * We don't do ShowPosition() or ShowView() here, but let the update * routine in the window handler do it for the first time when * the window is exposed. */ netInit(); StartDisplay(); RatCursor(); }
void YubikoOtpKeyConfig::load() { BOOST_LOG_NAMED_SCOPE("YubikoOtpKeyConfig::load"); const string myInFile = checkFileName(false); ptree myTree; read_json(myInFile, myTree); const string myVer(myTree.get<string>(K_NM_DOC_VERS)); BOOST_LOG_TRIVIAL(info)<< K_NM_VERS << ":" << myVer; setPrivateId(myTree.get<string>(K_NM_DOC_PRIV_ID)); setPublicId(myTree.get<string>(K_NM_DOC_PUB_ID)); setSecretKey(myTree.get<string>(K_NM_DOC_SEC_KEY)); setTimestamp(UTimestamp(myTree.get<uint64_t>(K_NM_DOC_TIMESTAMP))); setCounter(myTree.get<uint8_t>(K_NM_DOC_SES_CNTR)); setCrc(myTree.get<uint16_t>(K_NM_DOC_CRC)); setRandom(myTree.get<uint16_t>(K_NM_DOC_RANDOM)); setUseCounter(myTree.get<uint8_t>(K_NM_DOC_USE_CNTR)); setDescription(myTree.get<string>(K_NM_DOC_DESC)); if (myVer != "0.0.1") { const string mySysUser { myTree.get<string>(K_NM_DOC_SYS_USER) }; if (!mySysUser.empty()) setSysUser(mySysUser); } itsChangedFlag = false; }
// Set this to a random transformation. inline void Transformation::setRandom() { setRandom(1.0, M_PI); }
RandomListNode *copyRandomList(RandomListNode *head) { copy(head); setRandom(head); return separate(head); }
int main() { srand(time(NULL)); const int Number_of_Rects = 5; // initialization Rect userRect(7, 5, 10, 9); // Controlled Square Size Rect * rect = new Rect[Number_of_Rects]; // creates an array of 5 rectangles. // Rect * rect1 = new Rect; // (1, 6, 5, 15) // rect1->setRandomByPointer(rect1); int userInput; for(int i = 0; i < Number_of_Rects; i++) // sets 5 rectanges to a random position { setRandom(rect[i]); } do { // draw for(int i = 0; i < Number_of_Rects; i++) // draw 5 rectangles that are numbered from 0 - 4 { rect[i].draw('0'+i); } //rect1->draw('1'); moveCursor(0, 0); // re-print instructions printf("move with 'w', 'a', 's', and 'd'"); userRect.draw('#'); moveCursor(40, 0); printf("No Collision"); checkCollision(userRect, rect, Number_of_Rects); // collision detection. Prints "+" if player collides with other Rects /*for(int i = 0; i < Number_of_Rects; ++i) // old collision detector { if(userRect.isOverlapping( rect[i] ) ) { userRect.draw('+'); moveCursor(40, 0); printf("Collision"); } else { moveCursor(40, 0); printf("No Collision"); } }*/ // user input userInput = _getch(); // update Vec2 move; switch(userInput) // takes userInput to move controlled rectangle { case 'w': move = Vec2( 0,-1); break; case 'a': move = Vec2(-1, 0); break; case 's': move = Vec2( 0,+1); break; case 'd': move = Vec2(+1, 0); break; } userRect.draw(' '); // un-draw before moving userRect.translate(move); // Draws square at new location }while(userInput != 27); // escape key delete [] rect; return 0; }
int menuArrowNext(){ HANDLE hendle = GetStdHandle(STD_OUTPUT_HANDLE); COORD coord; coord.X=33; coord.Y=11; int key=0; do { key=_gettch(); switch (key) { case 80: SetConsoleCursorPosition(hendle,coord); cout<<" "<<endl; coord.Y++; if(coord.Y>12){ coord.Y=12; } SetConsoleCursorPosition(hendle,coord); cout<<"->"<<endl; break; case 72: SetConsoleCursorPosition(hendle,coord); cout<<" "<<endl; coord.Y--; if(coord.Y<11){ coord.Y=11; } SetConsoleCursorPosition(hendle,coord); cout<<"->"<<endl; break; case 13: if(coord.Y==11){ system("CLS"); setRandom(tableHuman,4); setRandom(tableHuman,3); setRandom(tableHuman,3); setRandom(tableHuman,2); setRandom(tableHuman,2); setRandom(tableHuman,2); setRandom(tableHuman,1); setRandom(tableHuman,1); setRandom(tableHuman,1); setRandom(tableHuman,1); printTable(tableHuman,0,0); printTable(tableCpu,15,0); } if(coord.Y==12){ system("CLS"); setManual(); printTable(tableHuman,0,0); setManual(); printTable(tableHuman,0,0); setManual(); printTable(tableHuman,0,0); setManual(); printTable(tableHuman,0,0); setManual(); printTable(tableCpu,15,0); cout<<ship1; return 0; } break; case 27: menu(); break; } } while(key!=13); return 0; }
Generator::Generator(int seed, int tps) { setRandom(seed); interarrival = 1000 / tps; }