int64_t allocateArray(bool fRandom, int64_t cItems, int64_t ** aArray){ int64_t iret = 0; int64_t *ary = NULL; ary = (int64_t *) malloc(cItems * sizeof(int64_t)); if (NULL == ary) { printf("Out Of Memory in allocateArray\n"); iret = 1; // OUT OF MEMORY! } if (0 == iret) { //Initialize if (fRandom) { for (int64_t i = 0; i < cItems; i++) { ary[i] = randValue(cItems,i); } } else{ for (int64_t i = 0; i < cItems; i++) { ary[i] = rampValue(cItems,i); } } } if (0 == iret) { *aArray = ary; } else { free(ary); } return iret; }
perceptron::perceptron(int _n, perceptronType _type) { n = _n; w = new double[n + 1]; type = _type; // Init every weight with a rand between 0 an 1 for(int i = 0; i <= n ; i++) w[i] = randValue(1, -1); }
float PerlinNoiseGenerator::getHeight(int row, int col) { float result = 0; float amp = 1; //freq was originally 16.f, tweaked to make bigger hills float freq = 100.f; for (int i = 0; i < m_iter; ++i) { float new_row = row / freq; float new_col = col / freq; int row_floor = (int) glm::floor(new_row); float row_frac = glm::fract(new_row); int row_ceil = row_floor + 1; int col_floor = (int) glm::floor(new_col); float col_frac = glm::fract(new_col); int col_ceil = col_floor + 1; float A = randValue(row_floor, col_floor); float B = randValue(row_floor, col_ceil); float C = randValue(row_ceil, col_floor); float D = randValue(row_ceil, col_ceil); float smooth_col_frac = col_frac*col_frac*(3 - 2 * col_frac); float smooth_row_frac = row_frac*row_frac*(3 - 2 * row_frac); float AB = glm::mix(A, B, smooth_col_frac); float CD = glm::mix(C, D, smooth_col_frac); float ABCD = glm::mix(AB, CD, smooth_row_frac); result += ABCD * amp; amp /= 2.f; freq /= 2.f; } return (result + m_amplitude) / (2.f * m_amplitude); }
Condition::Condition(ConditionTest type, double extraValue) : mType(type) , mOperatorType(OperatorType::None) , mLCondition() , mRCondition() , mNeededValue(false) , mExtraInt(0) , mExtraDouble(extraValue) , mUnitType(BWAPI::UnitTypes::None) , mTech(BWAPI::TechTypes::None) , mUpgrade(BWAPI::UpgradeTypes::None) , mString() { if(type == ConditionTest::randomChance) { boost::mt19937 rng(static_cast<unsigned int>(std::time(0))); boost::uniform_real<> dist(0.0, 1.0); boost::variate_generator<boost::mt19937, boost::uniform_real<>> randValue(rng, dist); mNeededValue = (extraValue >= randValue()); } }
void ShadowrunTool::on_ini_roll_clicked() { //this->ui->output->setText(QString::number()); int initiative = 4+this->ui->spinData->value(); //QTime time = QTime::currentTime(); int rolledValues = initiative; int diceCount = 0; if(this->ui->coldsim->isChecked()) { diceCount = 3; if(this->ui->additionalIniDie->isChecked()) { diceCount++; } } if(this->ui->hotsim->isChecked()) { diceCount = 4; if(this->ui->additionalIniDie->isChecked()) { diceCount++; } } if(this->ui->arsim->isChecked()) { initiative = 6; diceCount = 1; } //qDebug() << "Wuerfle: " << diceCount << "Ini: " << initiative; for(int i = 0; i < diceCount; i++) { //time = QTime::currentTime(); //qsrand((uint) time.msec()); rolledValues+=(randValue(6, 1)); //QTest::qSleep(1); } this->ui->IniBar->setMaximum(100); this->ui->iniValue->setText(QString::number(rolledValues)); this->ui->IniBar->setValue(rolledValues); }
void ShadowrunTool::on_diceroll_clicked() { QList<int> rolledValues; int diceCount = this->ui->dicecount->value(); for(int i = 0; i < diceCount; i++) { rolledValues.append(randValue()); } //1: 2: 3: 4: 5: 6: int counter[6] = {0}; for(int i = 0; i < rolledValues.size(); i++) { if(rolledValues[i] == 1) { counter[0]++; } else if(rolledValues[i] == 2) { counter[1]++; } else if(rolledValues[i] == 3) { counter[2]++; } else if(rolledValues[i] == 4) { counter[3]++; } else if(rolledValues[i] == 5) { counter[4]++; } else if(rolledValues[i] == 6) { counter[5]++; } } QString output(" 1: "+QString::number(counter[0]) +"\n 2: "+QString::number(counter[1]) +"\n 3: "+QString::number(counter[2]) +"\n 4: "+QString::number(counter[3]) +"\n 5: "+QString::number(counter[4]) +"\n 6: "+QString::number(counter[5])); this->ui->rolledDice->setText(output); // set statistics if(counter[0] > rolledValues.size()/2) { this->ui->diceresults->setText("Würfel Egebnisse: \n Patzer"); if(counter[4] == 0 && counter[5] == 0 && counter[0]) { this->ui->diceresults->setText("Würfel Egebnisse: \n Kritischer Patzer"); } } else { this->ui->diceresults->setText(QString("Würfel Egebnisse: \n 5: ").append(QString::number(counter[4]).append(", 6: ").append(QString::number(counter[5]))).append(" Erfolge: ").append(QString::number(counter[4]+counter[5]))); } }