void digestBuf() { // Mangle the data for(size_t j = 0; j < 3; j++) { // Taint the bytes GAssert(DIGEST_BYTES >= 32); if(m_pTaint) Taint_buffer(m_pBuf, m_pTaint + (m_rand.next() % (DIGEST_BYTES - 32)), 32, j); // Shuffle the bytes shuffleBytes(m_pBuf, DIGEST_BYTES); // Hash each 64-bit chunk with sha-512 unsigned char* pChunk = m_pBuf; for(size_t i = 0; i < (DIGEST_BYTES / 64); i++) { sha512_ctx ctx; sha512_begin(&ctx); sha512_hash(pChunk, 64, &ctx); sha512_end(pChunk, &ctx); pChunk += 64; } } // Add it to the hash uint64_t* pA = (uint64_t*)m_pBuf; uint64_t* pB = (uint64_t*)m_pHash; for(size_t i = 0; i < (DIGEST_BYTES / sizeof(uint64_t)); i++) { (*pB) += (*pA); pB++; pA++; } }
void Iterate(bool forw) { g_updateView = m_pUpdateDisplay->isChecked(); if(!g_updateView && m_prng->next(8192) == 0) g_updateView = true; m_pModel->IterateModel(m_pBullets->selection(), forw); m_pCanvas->setImage(m_pImage); }
void wipe(unsigned char* pBuf, size_t len) { while(len > 0) { *(pBuf++) = (unsigned char)m_rand.next(); len--; } }
unsigned char* getHash() { if(m_remaining < DIGEST_BYTES) { while(m_remaining > 0) { *m_pPos = (unsigned char)m_rand.next(); m_pPos++; m_remaining--; } digestBuf(); m_remaining = DIGEST_BYTES; } return m_pHash; }
virtual void doJob(size_t jobId) { // Randomly draw some data (with replacement) GReleaseDataHolder hDrawnFeatures(&m_drawnFeatures); GReleaseDataHolder hDrawnLabels(&m_drawnLabels); for(size_t j = 0; j < m_drawSize; j++) { size_t r = (size_t)m_rand.next(m_features.rows()); m_drawnFeatures.takeRow((GVec*)&m_features[r]); // This case is only okay because we only use drawFeatures as a const GMatrix m_drawnLabels.takeRow((GVec*)&m_labels[r]); // This case is only okay because we only use drawnLabels as a const GMatrix } // Train the learner with the drawn data m_pBag->models()[jobId]->m_pModel->train(m_drawnFeatures, m_drawnLabels); }
void update() { m_x = MAX(0, MIN(200, m_x + (int)m_rand.next(15) - 7)); m_y = MAX(0, MIN(500, m_y + (int)m_rand.next(15) - 7)); }
void shuffleBytes(unsigned char* pBuf, size_t len) { for(size_t i = len; i > 1; i--) std::swap(pBuf[(size_t)m_rand.next(i)], pBuf[i - 1]); }