void TestRandom(void) /* ------------------------------------------------------------------ * Use this (optional) function to test for a correct implementation. * ------------------------------------------------------------------ */ { long i; long x; double u; char ok = 0; SelectStream(0); /* select the default stream */ PutSeed(1); /* and set the state to 1 */ for(i = 0; i < 10000; i++) u = Random(); GetSeed(&x); /* get the new state value */ ok = (x == CHECK); /* and check for correctness */ SelectStream(1); /* select stream 1 */ PlantSeeds(1); /* set the state of all streams */ GetSeed(&x); /* get the state of stream 1 */ ok = ok && (x == A256); /* x should be the jump multiplier */ if (ok) printf("\n The implementation of rngs.c is correct.\n\n"); else printf("\n\a ERROR -- the implementation of rngs.c is not correct.\n\n"); }
// This is the inititialization routine. This has to be called first! CALMAPI::CALMAPI( void ) { // store stream defaults, since we will be manipulating width and precision GetStreamDefaults(); // initialize the random number generator for the E-node activation SetSeed( GetSeed() ); // store the current working directory getcwd( mCALMCurDir, FILENAME_MAX ); strcpy( mCALMLogDir, mCALMCurDir ); // init log dir to same dir // Initialize and set the global network specifications data mNetwork = new CALMNetwork; mInput = NULL; mInputLen = 0; mNumRuns = 1; mNumEpochs = 50; mNumIterations = 100; mOrder = kPermuted; mVerbosity = O_WINNER; mConvstop = false; mFBOn = false; strcpy( mBasename, "calm" ); strcpy( mDirname, "." ); mLogFile = NULL; mCALMLog = &cout; }
void IntensityTransformer::Apply(cv::Mat &mat) { auto seed = GetSeed(); auto rng = m_rngs.pop_or_create([seed]() { return std::make_unique<std::mt19937>(seed); } ); // Using single precision as EigVal and EigVec matrices are single precision. std::normal_distribution<float> d(0, (float)m_curStdDev); cv::Mat alphas(1, 3, CV_32FC1); assert(m_eigVal.rows == 1 && m_eigVec.cols == 3); alphas.at<float>(0) = d(*rng) * m_eigVal.at<float>(0); alphas.at<float>(1) = d(*rng) * m_eigVal.at<float>(1); alphas.at<float>(2) = d(*rng) * m_eigVal.at<float>(2); m_rngs.push(std::move(rng)); assert(m_eigVec.rows == 3 && m_eigVec.cols == 3); cv::Mat shifts = m_eigVec * alphas.t(); // For multi-channel images data is in BGR format. size_t cdst = mat.rows * mat.cols * mat.channels(); ElemType* pdstBase = reinterpret_cast<ElemType*>(mat.data); for (ElemType* pdst = pdstBase; pdst < pdstBase + cdst;) { for (int c = 0; c < mat.channels(); c++) { float shift = shifts.at<float>(mat.channels() - c - 1); *pdst = std::min(std::max(*pdst + shift, (ElemType)0), (ElemType)255); pdst++; } } }
void CropTransformer::Apply(uint8_t copyId, cv::Mat &mat) { auto seed = GetSeed(); auto rng = m_rngs.pop_or_create([seed]() { return std::make_unique<std::mt19937>(seed); }); int viewIndex = m_cropType == CropType::MultiView10 ? (int)(copyId % ImageDeserializerBase::NumMultiViewCopies) : 0; switch (m_cropType) { case CropType::Center: mat = mat(GetCropRectCenter(mat.rows, mat.cols, *rng)); break; case CropType::RandomSide: mat = mat(GetCropRectRandomSide(mat.rows, mat.cols, *rng)); break; case CropType::RandomArea: mat = mat(GetCropRectRandomArea(mat.rows, mat.cols, *rng)); break; case CropType::MultiView10: mat = mat(GetCropRectMultiView10(viewIndex, mat.rows, mat.cols, *rng)); break; default: RuntimeError("Invalid crop type."); break; } // for MultiView10 m_hFlip is false, hence the first 5 will be unflipped, the later 5 will be flipped if ((m_hFlip && boost::random::bernoulli_distribution<>()(*rng)) || viewIndex >= 5) { cv::flip(mat, mat, 1); } m_rngs.push(std::move(rng)); }
void ScaleTransformer::Apply(cv::Mat &mat) { // If matrix has not been converted to the right type, do it now as rescaling // requires floating point type. // if (mat.type() != CV_MAKETYPE(m_dataType, m_imgChannels)) { mat.convertTo(mat, m_dataType); } auto seed = GetSeed(); auto rng = m_rngs.pop_or_create( [seed]() { return std::make_unique<std::mt19937>(seed); }); auto index = UniIntT(0, static_cast<int>(m_interp.size()) - 1)(*rng); assert(m_interp.size() > 0); cv::resize( mat, mat, cv::Size(static_cast<int>(m_imgWidth), static_cast<int>(m_imgHeight)), 0, 0, m_interp[index]); m_rngs.push(std::move(rng)); }
void Library_spot_native_Microsoft_SPOT_CryptoState::GetDeviceKey( RSAKey& key ) { KeySeed keySeed; GetSeed( keySeed ); ::Crypto_GeneratePrivateKey( &keySeed, &key ); }
void Library_spot_native_Microsoft_SPOT_CryptoState::GetDeviceKey( UINT8* key ) { KeySeed keySeed; GetSeed( keySeed ); ::GetC1Value( (BYTE*)&keySeed, key, TEA_KEY_SIZE_BYTES ); }
void GalaxySetupPanel::GetSetupData(GalaxySetupData& setup_data) const { setup_data.m_seed = GetSeed(); setup_data.m_size = Systems(); setup_data.m_shape = GetShape(); setup_data.m_age = GetAge(); setup_data.m_starlane_freq = GetStarlaneFrequency(); setup_data.m_planet_density = GetPlanetDensity(); setup_data.m_specials_freq = GetSpecialsFrequency(); setup_data.m_monster_freq = GetMonsterFrequency(); setup_data.m_native_freq = GetNativeFrequency(); setup_data.m_ai_aggr = GetAIAggression(); }
void TestRandom(void) /* * Use this (optional) procedure to test for a correct implementation. */ { long i; long x; double u; PutSeed(1); /* set initial state to 1 */ for(i = 0; i < 10000; i++) u = Random(); GetSeed(&x); /* get the new state */ if (x == CHECK) printf("\n The implementation of Random is correct\n"); else printf("\n\a ERROR - the implementation of Random is not correct\n"); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int ndims, len, i; int *dims; double *indata, *outdata; long ix,iy,iz; if((nlhs > 1) || (nrhs > 1)) mexErrMsgTxt("Usage: seed = randomseed; (or) randomseed(new_seed);"); if(nrhs > 0) { /* prhs[0] is first argument. * mxGetPr returns double* (data, col-major) */ ndims = mxGetNumberOfDimensions(prhs[0]); dims = (int*)mxGetDimensions(prhs[0]); indata = mxGetPr(prhs[0]); len = mxGetNumberOfElements(prhs[0]); if(mxIsSparse(prhs[0])) mexErrMsgTxt("Cannot handle sparse matrices. Sorry."); if(len == 1 && *indata == 0.0) { ResetSeed(); } else if(len != 3) { mexErrMsgTxt("seed must be 0 or a vector of 3 numbers."); } else { SetSeed((long)indata[0],(long)indata[1],(long)indata[2]); } } ndims = 1; dims = (int*)mxMalloc(sizeof(int)); dims[0] = 3; /* plhs[0] is first output */ plhs[0] = mxCreateNumericArray(ndims, dims, mxDOUBLE_CLASS, mxREAL); outdata = mxGetPr(plhs[0]); GetSeed(&ix,&iy,&iz); outdata[0] = (double)ix; outdata[1] = (double)iy; outdata[2] = (double)iz; }
// This is the inititialization routine. This has to be called first! SequenceAPI::SequenceAPI( void ) { // store stream defaults, since we will be manipulating width and precision GetStreamDefaults(); // initialize the random number generator for noise SetSeed( GetSeed() ); // store the current working directory getcwd( mSequenceCurDir, FILENAME_MAX ); strcpy( mSequenceLogDir, mSequenceCurDir ); // init log dir to same dir mPatterns = new Patterns(); // this just sets an empty pattern class // set defaults for the network specifications strcpy( mBasename, "seq" ); strcpy( mDirname, "." ); mNumFiles = 1; mFileIndex = 0; mRuns = 1; mEpochs = 1000; mIterations = 10; mRecallLen = 100; mNumLayers = 8; mLayerSize = 16; mContextSize = 16; mOrder = kPermutedOrder; mType = O_INF; mVerbosity = O_ERROR; mErrCrit = 0.1; mAlphaCrit = 0.01; mRecallCrit = 0.05; mTermNoise = 0.05; mError = -1.0; mOldInput = NULL; mNewInput = NULL; mInContext = NULL; mTextDisplay = NULL; mNetwork = NULL; mNoise = NULL; mSequenceLog = &cout; }
void BombObject::BeginEditParams(IObjParam *ip,ULONG flags,Animatable *prev) { this->ip = ip; if (!hParam) { hSot = ip->AddRollupPage( hInstance, MAKEINTRESOURCE(IDD_BOMB_SOT), DefaultSOTProc, GetString(IDS_RB_SOT), (LPARAM)ip,APPENDROLL_CLOSED); hParam = ip->AddRollupPage( hInstance, MAKEINTRESOURCE(IDD_BOMBPARAMS), BombParamProc, GetString(IDS_RB_BOMBPARAMS), (LPARAM)this ); } else { DLSetWindowLongPtr(hParam, this); // Init the dialog to our values. strengthSpin->SetValue(GetStrength(ip->GetTime()),FALSE); gravSpin->SetValue(GetGravity(ip->GetTime()),FALSE ); chaosSpin->SetValue(GetChaos(ip->GetTime()),FALSE ); detSpin->SetValue(GetDetonation(ip->GetTime()),FALSE ); spinSpin->SetValue(GetSpin(ip->GetTime()),FALSE); falloffSpin->SetValue(GetFalloff(ip->GetTime()),FALSE); minFragSpin->SetValue(GetMinFrag(ip->GetTime()),FALSE); maxFragSpin->SetValue(GetMaxFrag(ip->GetTime()),FALSE); seedSpin->SetValue(GetSeed(ip->GetTime()),FALSE); CheckDlgButton(hParam,IDC_FALLOFF_ON,GetFalloffOn(ip->GetTime())); } if (GetFalloffOn(ip->GetTime())) { NotifyDependents(FOREVER,0,REFMSG_CHANGE); ip->RedrawViews(ip->GetTime()); } }
void CropTransformer::Apply(cv::Mat &mat) { auto seed = GetSeed(); auto rng = m_rngs.pop_or_create( [seed]() { return std::make_unique<std::mt19937>(seed); }); double ratio = 1; switch (m_jitterType) { case RatioJitterType::None: ratio = m_cropRatioMin; break; case RatioJitterType::UniRatio: if (m_cropRatioMin == m_cropRatioMax) { ratio = m_cropRatioMin; } else { ratio = UniRealT(m_cropRatioMin, m_cropRatioMax)(*rng); assert(m_cropRatioMin <= ratio && ratio < m_cropRatioMax); } break; default: RuntimeError("Jitter type currently not implemented."); } mat = mat(GetCropRect(m_cropType, mat.rows, mat.cols, ratio, *rng)); if (m_hFlip && std::bernoulli_distribution()(*rng)) { cv::flip(mat, mat, 1); } m_rngs.push(std::move(rng)); }
void ColorTransformer::Apply(cv::Mat &mat) { auto seed = GetSeed(); auto rng = m_rngs.pop_or_create([seed]() { return std::make_unique<std::mt19937>(seed); }); if (m_curBrightnessRadius > 0 || m_curContrastRadius > 0) { // To change brightness and/or contrast the following standard transformation is used: // Xij = alpha * Xij + beta, where // alpha is a contrast adjustment and beta - brightness adjustment. ElemType beta = 0; if (m_curBrightnessRadius > 0) { UniRealT d(-m_curBrightnessRadius, m_curBrightnessRadius); // Compute mean value of the image. cv::Scalar imgMean = cv::sum(cv::sum(mat)); // Compute beta as a fraction of the mean. beta = (ElemType)(d(*rng) * imgMean[0] / (mat.rows * mat.cols * mat.channels())); } ElemType alpha = 1; if (m_curContrastRadius > 0) { UniRealT d(-m_curContrastRadius, m_curContrastRadius); alpha = (ElemType)(1 + d(*rng)); } // Could potentially use mat.convertTo(mat, -1, alpha, beta) // but it does not do range checking for single/double precision matrix. saturate_cast won't work either. size_t count = mat.rows * mat.cols * mat.channels(); ElemType* pbase = reinterpret_cast<ElemType*>(mat.data); for (ElemType* p = pbase; p < pbase + count; p++) { *p = std::min(std::max(*p * alpha + beta, (ElemType)0), (ElemType)255); } } if (m_curSaturationRadius > 0 && mat.channels() == 3) { UniRealT d(-m_curSaturationRadius, m_curSaturationRadius); double ratio = 1.0 + d(*rng); assert(0 <= ratio && ratio <= 2); auto hsv = m_hsvTemp.pop_or_create([]() { return std::make_unique<cv::Mat>(); }); // To change saturation, we need to convert the image to HSV format first, // the change S channgel and convert the image back to BGR format. cv::cvtColor(mat, *hsv, CV_BGR2HSV); assert(hsv->rows == mat.rows && hsv->cols == mat.cols); size_t count = hsv->rows * hsv->cols * mat.channels(); ElemType* phsvBase = reinterpret_cast<ElemType*>(hsv->data); for (ElemType* phsv = phsvBase; phsv < phsvBase + count; phsv += 3) { const int HsvIndex = 1; phsv[HsvIndex] = std::min((ElemType)(phsv[HsvIndex] * ratio), (ElemType)1); } cv::cvtColor(*hsv, mat, CV_HSV2BGR); m_hsvTemp.push(std::move(hsv)); } m_rngs.push(std::move(rng)); }
void testAdventurer (struct gameState *after) { int numTreasureDrawn = 0; int numNonTreasureDrawn = 0; int nonTreasureSaved; int cardDrawn; int temphand[MAX_HAND]; int result, randomDeterminer; int handPos = floor(Random() * after->handCount[after->whoseTurn]); // Sets up call to random number generator long *x = malloc(sizeof(long)); struct gameState before; //Copy two gameStates so that they can be compared later memcpy(&before, after, sizeof(struct gameState)); randomDeterminer = floor(Random() * 10); if (randomDeterminer <= 5) after->deckCount[after->whoseTurn] = 0; // Gets seed so random number sequence can be repeated for before gameState GetSeed(x); //Testing adventurer refactored on after gameState result = cardEffect(adventurer, 0, 0, 0, after, handPos, 0); // Enters seed so that random number sequence will be the same for post gameState PutSeed(*x); //Give gameState before the correct implementation of Adventurer while (numTreasureDrawn < 2) { if (before.deckCount[before.whoseTurn] < 1) //shuffle discard { shuffle(before.whoseTurn, &before); } drawCard(before.whoseTurn, &before); cardDrawn = before.hand[before.whoseTurn][before.handCount[before.whoseTurn] - 1]; if (cardDrawn == copper || cardDrawn == silver || cardDrawn == gold) { numTreasureDrawn++; } else { temphand[numNonTreasureDrawn] = cardDrawn; before.handCount[before.whoseTurn]--; //Remove (discard) if not treasure numNonTreasureDrawn++; } } nonTreasureSaved = numNonTreasureDrawn; //Number of cards in discard pile before adding temp hand int discardCountBeforeExecution = before.discardCount[before.whoseTurn]; while (numNonTreasureDrawn - 1 >= 0) { before.discard[before.whoseTurn][before.discardCount[before.whoseTurn]++] = temphand[numNonTreasureDrawn-1]; numNonTreasureDrawn--; } //Now, compare to after, should equal old + number of non-treasure cards drawn int discardCountAfterExecution = before.discardCount[before.whoseTurn]; assert(discardCountAfterExecution == discardCountBeforeExecution + nonTreasureSaved); //Now, check that the function returned correctly and the gameStates are equal assert(result == 0); //Should fail (in refactor, gives 3 treasure cards) if (memcmp(&before, after, sizeof(struct gameState)) != 0) { printf("Game states were not equal (bug(s) present)!\n"); exit(0); } return; }
Std_ReturnType Diag_GetSeedEXTDS(uint8 *securityAccessDataRecord, uint8 *seed, Dcm_NegativeResponseCodeType *errorCode) { return GetSeed(securityAccessDataRecord,seed,errorCode); }