inline void LifeGamev2::init(std::vector<std::vector<Grayscale>> &universe) { for (auto &line : universe) { for (auto &u : line) { u = myRandom() % 128; if(myRandom() % 100 < DENSITY) { u = 128 + myRandom() % 128; } } } }
Sphere::Sphere() { set(¢er.location, (myRandom() - 0.5)*XRange, 0.0, 0.0); center.speed.x = (myRandom() - 0.5)*5; center.speed.y = (myRandom() + 0.5)*7.5; center.speed.z = (myRandom() - 0.5)*5; set(¢er.acceleration, 0, 0-GRAVITY_POWER, 0); radius = (myRandom() + 0.5)*defaultRadius; center.ttl = int((myRandom() + 0.5)*SPHERE_TTL); number_of_particles = int((myRandom() + 0.5)*SPHERE_PARTICLES); set(&(center.color), myRandom(), myRandom(), myRandom()); }
void setShake() { if( MaxShake !=0 ) { shakeX = myRandom(-MaxShake , MaxShake); shakeY = myRandom(-MaxShake , MaxShake); } else { shakeX = shakeY = 0; } if(rc) glColor3f(myRandom(0.1,1),myRandom(0.1,1),myRandom(0.1,1)); }
void CMyProblem::GenerateRandomProblemWNC(int _n, int _p, string _name, int max_w) { _alloc(_n); Set_p(_p); Set_name(_name.c_str()); for (int i=0; i<n; i++) { r[i]=myRandom(0, p*i); w[i]=myRandom(1,(max_w!=0)?max_w:100); //cout << r[i] << ' ' << w[i]<< endl; } //cout << endl; }
void ME_Regression_DataSet::randomly_remove_samples_with_activated_feature(int label, int feature_idx, float prob_remove) { const int org_size = samples.size(); int num_removed=0; int i; int num_bad = 0; for (i=0; i<samples.size(); i++) { if (samples[i].label != label) continue; if (samples[i].get_feature_value(feature_idx) == 0) continue; num_bad++; if (myRandom() < prob_remove) { samples[i]=samples[samples.size()-1]; samples.pop_back(); num_removed++; } } cout << "Removed " << num_removed << "/" << num_bad << endl; cout << "Original size " << org_size << ", now " << samples.size() << endl; tally_samples(); }
void generateLayers() { int i; for (i = 0; i < LAYERS; i++) layer[i].first = NULL; int j; for (i = 0; i < LAYERS; i++) { for (j = 0; j < BOXES; j++) { Layer_addBox(&layer[i], Box_new(myRandom(WIDTH), myRandom(HEIGHT), myRandom(i*j) * 4, myRandom(10) + 5)); //Layer_addBox(&layer[i], Box_new(0, 0, 0, 50)); } } }
Particle::Particle(Sphere *s) { //location location.x = s->center.location.x + 2*(myRandom() - 0.5);//*s->radius; location.y = s->center.location.y + 2*(myRandom() - 0.5);//*s->radius; location.z = s->center.location.z + 2*(myRandom() - 0.5);//*s->radius; //speed speed.x = (myRandom() - 0.5)*8; speed.y = (myRandom() - 0.5)*8; speed.z = (myRandom() - 0.5)*8; //setting accelaration set(&acceleration, 0, 0-GRAVITY_POWER*0.5, 0); //setting color set(&color, s->center.color.x, s->center.color.y, s->center.color.z); //changing speed add(&speed, &(s->center.speed)); //changing acceleration add(&acceleration, &(s->center.acceleration)); //lifetime of the particle ttl = int((myRandom() + 0.5)*PARTICLE_TTL); }
/*! Generations des sites */ void selectPoints (void) { int n = nbPoints; rectangleEnglobantPolygone(); while (--n >= 0) { T[n].coords[0] = myRandom(0, 400); T[n].coords[1] = myRandom(0, 400); } Orientation orient = orientationPolaire(T[0],T[1],T[2]); if( orient == ALIGNES) selectPoints(); else if(orient == DROITE) // réorganisation des points dans l'ordre trigo { vertex tampon = T[1]; T[1] = T[2]; T[2] = tampon; } }
void NetInterface::initRandomData() { mRandomDataInitialized = true; U32 seed = Platform::getRealMilliseconds(); if(Journal::IsPlaying()) Journal::Read(&seed); else if(Journal::IsRecording()) Journal::Write(seed); MRandomR250 myRandom(seed); for(U32 i = 0; i < 12; i++) mRandomHashData[i] = myRandom.randI(); }
State BatManager::updateBat() { if (time==0) { currentState.heading = myRandom( -3*PI/4, -PI/4); currentState.x = myRandom(-3, 3); currentState.y = myRandom(28, 30); time++; return currentState; } State newState; newState.speed = velocityDist.getRand(4.81, 2.18); double desiredHeading; if (flight == 1 && myRandom(0, 1) < 0.05) { flight = 0; leader = NULL; //std::cout << "changed "; } //std::cout << flight << std::endl; std::map<double, Prey*>::iterator closestPrey = identifiedPreys.begin(); if (closestPrey != identifiedPreys.end()) { double preyX, preyY; preyX = closestPrey->second->currentState.x, preyY = closestPrey->second->currentState.y; double distance = Distance(currentState.x, currentState.y, preyX , preyY); double dotProduct = ((preyX - currentState.x)); double cosAngle = dotProduct / distance; if (preyY < currentState.y) desiredHeading = -acos(cosAngle); else desiredHeading = acos(cosAngle); } else if (!flight || (flight && leader->time<delay) ) { desiredHeading = (*(gcnew VonMisesDist(currentState.heading, 557))).getRand(); //std::cout << desiredHeading << std::endl; } else { std::map<int, State>::iterator leaderPos = leader->prevStates.find(time - delay); if (leaderPos != leader->prevStates.end()) { //std::cout << leaderPos->second.heading; desiredHeading = (*(gcnew VonMisesDist((currentState.heading + leaderPos->second.heading)/2, 2473))).getRand(); } } double headingChange = desiredHeading - currentState.heading; double maxAngularChange = 4 * 9.81 / 50 / newState.speed; if ((abs(headingChange)) < (maxAngularChange) ) newState.heading = desiredHeading; else if (headingChange < maxAngularChange) newState.heading = currentState.heading - maxAngularChange; else newState.heading = currentState.heading + maxAngularChange; double a = cos(newState.heading); double b = sin(newState.heading); newState.x = currentState.x + newState.speed * 1 / 50 * cos(newState.heading); newState.y = currentState.y + newState.speed * 1 / 50 * sin(newState.heading); if (prevStates.size() == 1000) prevStates.erase(prevStates.begin()); prevStates.insert(std::pair<int, State>(time, currentState)); time = time + 1; currentState = newState; return newState; }