std::string createPassword( const AllowedCharacters& allowedCharacters, std::size_t length ) { std::string password; if( !allowedCharacters.letters && !allowedCharacters.numbers && !allowedCharacters.specials ) //nothing allowed { return password; } std::mt19937 rng; rng.seed( time( nullptr ) ); while( password.length() != length ) { std::uniform_int_distribution< int32_t > distForChoice( 1, 4 ); auto choice( distForChoice( rng ) ); if ( choice == 1 && allowedCharacters.letters ) //small letters { std::uniform_int_distribution< int32_t > distForSmallLetters( 97, 122 ); password += static_cast< char >( distForSmallLetters( rng ) ); } if ( choice == 2 && allowedCharacters.letters ) //big letters { std::uniform_int_distribution< int32_t > distForBigLetters( 65, 90 ); password += static_cast< char >( distForBigLetters( rng ) ); } if ( choice == 3 && allowedCharacters.numbers ) //numbers 0-9 { std::uniform_int_distribution< int32_t > distForNumbers( 0, 9 ); password += std::to_string( distForNumbers( rng ) ); } if ( choice == 4 && allowedCharacters.specials ) //special characters { std::uniform_int_distribution< int32_t > distForSpecialCharacters( 1, 5 ); auto specialCharactersChoice( distForSpecialCharacters( rng ) ); if( specialCharactersChoice == 1 ) { password += '!'; } if( specialCharactersChoice == 2 ) { password += '?'; } if( specialCharactersChoice == 3 ) { password += '#'; } if( specialCharactersChoice == 4 ) { password += '$'; } if( specialCharactersChoice == 5 ) { password += '&'; } } } return password; }
void ReserveRetunrHomeController::initGame() { Size winSize = Director::getInstance()->getVisibleSize(); auto _bg2 = LayerColor::create(Color4B(0,128,128,128), winSize.width, winSize.height); this->addChild(_bg2); std::vector<std::string>filename = { "river-932131_640.png", "city-918523_640.png", "avenue-957201_640.png" }; std::random_device device; std::mt19937 mt(device()); std::default_random_engine _engine = std::default_random_engine(mt()); //取り出す値を設定(int型) std::discrete_distribution<int> distForNumbers = std::discrete_distribution<int>{0,1,2}; //実際に利用 int index = distForNumbers(_engine); if(_reserveReturne){ Label *label = Label::createWithSystemFont("帰宅予約の案内中", "Marker Felt.ttf", 24); label->setScale(2.0f); label->setPosition(Vec2(winSize.width/2, winSize.height*3/4)); this->addChild(label); Label *label1 = Label::createWithSystemFont("ご自宅までの残り時間と残り距離", "Marker Felt.ttf", 18); label1->setScale(2.0f); label1->setPosition(Vec2(winSize.width/2, winSize.height/2)); this->addChild(label1); NativeLauncher::getNewLocation_latitude(); NativeLauncher::getNewLocation_longitude(); NativeLauncher::getNewLocation_speed(); NativeLauncher::getNewLocation_course(); NativeLauncher::getDestance(); std::string temo = std::to_string(round(NativeLauncher::getDestance()/1000)) + "km\n残り" + std::to_string(round((NativeLauncher::getDestance()/NativeLauncher::getNewLocation_speed())/60)) + "分"; Label *label3 = Label::createWithSystemFont(temo, "Marker Felt.ttf", 18); label3->setScale(2.0f); label3->setPosition(Vec2(winSize.width/2, winSize.height/2-70)); this->addChild(label3); }else{ _sprite1 = Sprite::create(filename[index]); _sprite1->setScale(1.0f); _sprite1->setPosition(Vec2(winSize.width/2, winSize.height/2)); addChild(_sprite1); Label *label = Label::createWithSystemFont("帰宅予約を案内できます", "Marker Felt.ttf", 24); label->setScale(2.0f); label->setPosition(Vec2(winSize.width/2, winSize.height*3/4)); this->addChild(label); } // platform::NativeBridge::executeNative(); //update関数の呼び出しを開始 scheduleUpdate(); }