void CTerrain::init(void) { int i, j, k; for (i = 0 ; i < BB ; i++) { p[i] = i; g1[i] = (float)((myRand() % (BB + BB)) - BB) / BB; for (j = 0 ; j < 2 ; j++) g2[i][j] = (float)((myRand() % (BB + BB)) - BB) / BB; normalize2(g2[i]); for (j = 0 ; j < 3 ; j++) g3[i][j] = (float)((myRand() % (BB + BB)) - BB) / BB; normalize3(g3[i]); } while (--i) { k = p[i]; p[i] = p[j = myRand() % BB]; p[j] = k; } for (i = 0 ; i < BB + 2 ; i++) { p[BB + i] = p[i]; g1[BB + i] = g1[i]; for (j = 0 ; j < 2 ; j++) g2[BB + i][j] = g2[i][j]; for (j = 0 ; j < 3 ; j++) g3[BB + i][j] = g3[i][j]; } }
/* * Add bits of given value to the signature. */ void signValue(BloomState *state, SignType *sign, Datum value, int attno) { uint32 hashVal; int nBit, j; /* * init generator with "column's" number to get "hashed" seed for new * value. We don't want to map the same numbers from different columns * into the same bits! */ mySrand(attno); /* * Init hash sequence to map our value into bits. the same values in * different columns will be mapped into different bits because of step * above */ hashVal = DatumGetInt32(FunctionCall1(&state->hashFn[attno], value)); mySrand(hashVal ^ myRand()); for (j = 0; j < state->opts.bitSize[attno]; j++) { /* prevent mutiple evaluation */ nBit = myRand() % (state->opts.bloomLength * BITSIGNTYPE); SETBIT(sign, nBit); } }
Node::Node(){ _nodeType = TERM; _termKind = (TermKind)(myRand() % TERM_KIND_NUM); _left = NULL; _right = NULL; _val = myRand() % SENSOR_NUM; }
int LinearGenerator::toGenerate() { setSeed(myRand()); while((getSeed() > getMaxValue()) || (getSeed() < getMinValue())) setSeed(myRand()); print(std::cout); return getSeed(); }
void fillTab(int *x, int theSize){ int i,j; for (i=0;i<theSize;i++){ x[i] = myRand(0, theSize*10); for(j=0;j<i-1;j++){ if(x[j]==x[i]){ x[j] = myRand(0, theSize*10); } } } }
void testrand(unsigned cnt) { while (cnt--) { unsigned v; v = myRand() & 0x7FFF; v = (v << 15) | (myRand() & 0x7FFF); v = (v << 1) | (myRand() & 0x1); test10(v); } }
void Node::addTerm(){ if(_nodeType == OP){ if(myRand()%2) _left->addTerm(); else _right->addTerm(); return; } _nodeType = OP; _opKind = (OpKind)(myRand() % OP_KIND_NUM); _left = new Node(); _right = new Node(); }
void RS_Engine::new_block() { if( block != NULL ) { BlockFactory::destroyBlock( block ); } BlockType newType = (BlockType)myRand(7); int unit_value = myRand(6); qDebug("type:%d, color:%d", newType, unit_value); block = BlockFactory::createBlock( newType , unit_value , units ); }
double run_optim_full_calcA2(const genome &g,const std::vector<perChr>&pc,para&p){ toOptim2 *to = new toOptim2(g,pc); double tsk[4];//tmparray used of saving stackpointers to->tsk = tsk; double pars[2]; pars[0]=myRand(0,1);pars[1]=myRand(0,1-pars[0]); //fix last pars double lbd[2]={0.000001,0.000001}; double ubd[2]={0.999999,0.999999}; int nbd[2]={2,2}; double opt= -findmax_bfgs(2,pars,(void *)to, bfgs_call_full_calcA2,NULL,lbd, ubd,nbd, -1); p.k0=pars[0]; p.k1=pars[1]; p.k2=1-pars[0]-pars[1]; p.a=calculateA(p.k0,p.k1,p.k2,PHI); return opt; }
void FieldBackStone::init(const int32_t &x, const int32_t &y) { FieldBack::init(x, y); switch (myRand(x ^ (y<<2)) % 6) { case 0: image = load_image("Background/Erze/Steine/Steine01.png"); break; case 1: image = load_image("Background/Erze/Steine/Steine02.png"); break; case 2: image = load_image("Background/Erze/Steine/Steine03.png"); break; case 3: image = load_image("Background/Erze/Steine/Steine04.png"); break; case 4: image = load_image("Background/Erze/Steine/Steine05.png"); break; case 5: image = load_image("Background/Erze/Steine/Steine06.png"); break; } }
void FieldBackSilver::init(const int32_t &x, const int32_t &y) { FieldBack::init(x, y); switch (myRand(x ^ (y<<2)) % 6) { case 0: image = load_image("Background/Erze/Silber/Silber01.png"); break; case 1: image = load_image("Background/Erze/Silber/Silber02.png"); break; case 2: image = load_image("Background/Erze/Silber/Silber03.png"); break; case 3: image = load_image("Background/Erze/Silber/Silber04.png"); break; case 4: image = load_image("Background/Erze/Silber/Silber05.png"); break; case 5: image = load_image("Background/Erze/Silber/Silber06.png"); break; } }
Node* GenLvalExpr(void) { Node* n = NewNode(); n->type = 'L'; n->varNum = VarCnt++; n->varVal = myRand() & 3; return n; }
void createRandGridMembers(GridMember** memberList) { int i, j; for(i=0; i<20; i++) { for(j=0; j<20; j++) { memberList[i][j].alive = myRand(); memberList[i][j].no_of_neighbours = 0; } } }
double run_optim_full2(const genome &g,const std::vector<perChr>&pc,para&p){ toOptim2 *to = new toOptim2(g,pc); double tsk[4];//tmparray used of saving stackpointers to->tsk = tsk; double pars[3];pars[0]=myRand(alim[0],alim[1]); pars[1]=myRand(0,1);pars[2]=myRand(0,1-pars[1]); //double pars[3];pars[0]=myRand(alim[0],alim[1]); pars[1]=myRand(0,1);pars[2]=1-pars[1];pars[2]=0; // double pars[3]={0.045854, 0.823746,0.176254}; //fix last pars double lbd[3]={alim[0],0.000001,0.000001}; double ubd[3]={alim[1],0.999999,0.999999}; int nbd[3]={2,2,2}; double opt= -findmax_bfgs(3,pars,(void *)to, bfgs_call_full2,NULL,lbd, ubd,nbd, -1); p.a=pars[0]; p.k0=pars[1]; p.k1=pars[2]; p.k2=1-pars[1]-pars[2]; return opt; }
string Dictonary::randomItem() { srand (time(NULL)); randNum = myRand(0,10); if((ITEMS.at(randNum)).empty()) this -> randomItem(); return (ITEMS.at(randNum)); }
void pulse() { const signed char bitesize = 30; for (unsigned char i=0; i<NUMCH; i++) { float rnd = myRand(); speed[i] += 20*(rnd - .5); if (rnd < 0.01) { speed[i] *= 1.1; } else { speed[i] = speed[i] * 0.99; } if (rnd < 0.5 && rnd > 0.4993) { //every 10000 or so, add bias of up to 10000 buffA[i] = myRand() * 60000 - 30000; } if (rnd < 0.6 && rnd > 0.599) { speed[i] = -speed[i]; } if (absFloat(speed[i]) > SCHARMAX) { speed[i] *= 0.5; } signed char dBright = myRound(speed[i]); if (buffA[i] != 0 && dBright <= SCHARMAX-bitesize && dBright >= -SCHARMAX+bitesize) { if (buffA[i] < 0) { dBright-=10; buffA[i]+=10; } else { dBright+=10; buffA[i]-=10; } if (absFloat(buffA[i]) < 10) { buffA[i] = 0; } } signed char bndRes = boundShort(&brightness[i], &dBright); if (bndRes != 0) { speed[i] = -.5*speed[i]; } } }
void CNeuron::setNumOfWeights(int n) { m_numOfInputs = n; m_w = new real[m_numOfInputs + 1]; /// The +1 part is for the BIAS if (!m_w) { std::cerr << "Uh oh, no memory for weights..." << std::endl; return; } real sum = 0; for (int i = 0; i < m_numOfInputs + 1; ++i) sum += m_w[i] = myRand(-1.0, 1.0); //std::cout << "Average = " << sum/m_numOfInputs << std::endl; }
//Generates a map with random cells. void buildMap() { clearMap(); int i, j; for ( i = 0; i < 30; i++ ) { for ( j = 0; j < 30; j++ ) { currentMap[i][j] = myRand(2); } } }
int play(int _player) { int rndCol = myRand(0,6); // Check row if empty int i; for (i = 0; i < ROW; i++) { if (grid[i][rndCol] == 0) { grid[i][rndCol] = _player; break; } } return 0; }
void *producer(void *param) { int random; int r; while(TRUE) { r = rand() % MAX_SLEEP; sleep(r); random = myRand(); printf("Producer %lu tries to insert %d at time %d\n", pthread_self(), random, buffer_time); if(insert_item(random)) fprintf(stderr, "Error"); } }
double run_optim_k2zero_calcA2(const genome &g,const std::vector<perChr>&pc,para&p){ toOptim2 *to = new toOptim2(g,pc); double tsk[4];//tmparray used of saving stackpointers to->tsk = tsk; double pars[1]={myRand(0,1)}; // fprintf(stderr,"pars=%f\n",pars[0]); double lbd[1]={0.000001}; double ubd[1]={0.999999}; int nbd[1]={2}; double opt= -findmax_bfgs(1,pars,(void *)to, bfgs_call_k2zero_calcA2,NULL,lbd, ubd,nbd, -1); p.k0=pars[0]; p.k1=1-p.k0; p.k2=0; p.a=calculateA(p.k0,p.k1,p.k2,PHI); return opt; }
void ParticleGenerator::initParticles() { for(int i=0; i<mMaxParticles; i++) // Boucle sur toutes les particules { mParticles[i].active = true; // On rend la particule active mParticles[i].life = 1.0; // Maximum de vie mParticles[i].fade = myRand(0.001,0.005); // Vitesse de disparition aléatoire mParticles[i].r=myRand(0.0,1.0); // Quantité aléatoire de Rouge mParticles[i].g=myRand(0.0,1.0); // Quantité aléatoire de Vert mParticles[i].b=myRand(0.0,1.0); // Quantité aléatoire de Bleu mParticles[i].xi = myRand(-1.0,1.0); // Vitesse aléatoire mParticles[i].yi = myRand(-1.0,1.0); mParticles[i].zi = myRand(1.0,2.0); mParticles[i].size = 0.1; } }
int inject_8_low_error( int pid, long pos ) { int iRet; long origData; long newData; ////read iRet = ptraceGetReg( pid, pos, origData ); if( iRet == RT_FAIL ) { return RT_FAIL; } //low 8 bits random error newData = origData ^ ( myRand() & 0x00000000000000ffL ); ////write iRet = ptraceSetReg( pid, pos, newData ); if( iRet == RT_FAIL ) { return RT_FAIL; } cout << "Fault on " << offset2name( pos ) << "(0X" << hex << origData << " -> 0X" << newData << ")" << dec << endl; return RT_OK; }
void pulseSweepInit() { for (unsigned int i=0; i<NUMCH; i++) { speed[i] = 2 * myRand() + 0.1; } }
void weaponSmg::shoot(double x, double y) { double a = atan2(y - (owner->y()+owner->h()/2), x - (owner->x()+owner->w()/2)); if (cooldown == 0) { if (ammoLoad > 0) { owner->core->createBullet(owner->id(), owner->x() + owner->w()/2, owner->y() + owner->h()/2, a + myRand(-0.05, 0.05), baseDamage); ammoLoad--; cooldown = cooldownTime; } else reload(); } }
void weaponShotgun::shoot(double x, double y) { double a = atan2(y - (owner->y()+owner->h()/2), x - (owner->x()+owner->w()/2)); if (cooldown == 0) { if (ammoLoad > 0) { for (int i=0; i<6; i++) owner->core->createBullet(owner->id(), owner->x() + owner->w()/2, owner->y() + owner->h()/2, a + myRand(-0.1, 0.1), baseDamage); ammoLoad--; cooldown = cooldownTime; } else reload(); } }
int randBool(void) { return myRand() < (int)RAND_MAX / 2; }
Node* genSubExpr(int depth, int lvalNeeded) { Node *n = newNode(), *left = NULL, *right = NULL, *cond = NULL; if (lvalNeeded) { lval: n->type = ntVar; n->base = randBool() ? bsInt : (randBool() ? bsShort : bsChar); n->sign = randBool() ? sgnSigned : sgnUnsigned; genVal(n); n->varNum = varCnt++; n->struc = randBool() ? strVar : strArrEl; n->storage = randBool() ? srgAuto : srgStatic; return n; } if (depth <= 1) { if (randBool()) goto lval; n->type = ntVal; n->base = bsInt; n->sign = randBool() ? sgnSigned : sgnUnsigned; genVal(n); return n; } n->type = ntOperator; if (randBool()) { n->op = opUnaryFirst + myRand() % (opUnaryLast + 1 - opUnaryFirst); lvalNeeded = operatorNeedsLvalue(n->op); left = genSubExpr(depth - 1, lvalNeeded); } else { int divguard = 0, shiftguard = 0; n->op = opBinaryFirst + myRand() % (opBinaryLast + 1 - opBinaryFirst); switch (n->op) { case opDiv: case opMod: case opAssignDiv: case opAssignMod: divguard = 1; break; case opShl: case opShr: case opAssignShl: case opAssignShr: shiftguard = 1; break; default:; } lvalNeeded = operatorNeedsLvalue(n->op); if (n->op == opCond) cond = genSubExpr(depth - 1, 0); left = genSubExpr(depth - 1, lvalNeeded); right = genSubExpr(depth - 1, 0); if (divguard || shiftguard) { // Prevent division by 0 and shifts by more than 31 and less than 0 Node *n1 = newNode(), *n2 = newNode(); n1->type = ntOperator; n1->op = divguard ? opOr : opAnd; n2->type = ntVal; n2->val = divguard ? 1 : 31; n2->base = bsInt; n2->sign = sgnSigned; attach2Nodes(n1, right, n2); right = n1; } } attach2Nodes(n, left, right); n->child[2] = cond; return n; }
void genVal(Node* n) { n->val = myRand() % 255 - 127; truncVal(n); }
void ParticleGenerator::render() { glPushAttrib(GL_ALL_ATTRIB_BITS); // Right and up direction of camera float r[3], u[3]; camera_directions(r,u,NULL); static int iteration = 0; // mShader.enable(); // mShader.setFloat("nbActiveModifier", mColorModifiers.size()); // mShader.setFloatArray("modifiersDistance", mModifiersDistance); // mShader.setVec3Array("colorModiers", mColorModifiers); // // mShader.setFloat("nbActiveForces", mForces.size()); // mShader.setVec3Array("forces", mForces); // mShader.setFloat("iteration", iteration++); glPushMatrix(); int a = 0; for(int i=0; i<mMaxParticles; i++) // For each particle { if(mParticles[i].active) // If it is active { float x = mParticles[i].x; // Get its position float y = mParticles[i].y; float z = mParticles[i].z; /* Particle color, transparence is life */ glColor4d(mParticles[i].r, mParticles[i].g, mParticles[i].b, mParticles[i].life); glBegin(GL_TRIANGLE_STRIP); float size = mParticles[i].size; glVertex3f(size*(x+r[0]+u[0]),size*(y+r[1]+u[1]),size*(z+r[2]+u[2])); glVertex3f(size*(x-r[0]+u[0]),size*(y-r[1]+u[1]),size*(z-r[2]+u[2])); glVertex3f(size*(x+r[0]-u[0]),size*(y+r[1]-u[1]),size*(z+r[2]-u[2])); glVertex3f(size*(x-r[0]-u[0]),size*(y-r[1]-u[1]),size*(z-r[2]-u[2])); glEnd(); /* Move particles */ mParticles[i].x += mParticles[i].xi; mParticles[i].y += mParticles[i].yi; mParticles[i].z += mParticles[i].zi; /* Apply forces */ std::vector<sf::Vector3f>::const_iterator it; for(it = mForces.begin(); it != mForces.end(); it++) { mParticles[i].x += (*it).x; mParticles[i].y += (*it).y; mParticles[i].z += (*it).z; } //std::cerr << "m "<< x << "\t" << y << "\t" << z << std::endl; mParticles[i].life -= mParticles[i].fade; /* If particle died, we regenerate it */ if (mParticles[i].life < 0.0) { mParticles[i].life = 1.0; // Full life mParticles[i].fade = myRand(0.01,0.05); mParticles[i].x = 0.0; // Put particle back to the emitter mParticles[i].y = 0.0; mParticles[i].z = 0.0; mParticles[i].xi = myRand(-10.0,10.0); // Random speed mParticles[i].yi = myRand(-10.0,10.0); mParticles[i].zi = myRand(10.0,20.0); mParticles[i].r=myRand(0.0,1.0); mParticles[i].g=myRand(0.0,1.0); mParticles[i].b=myRand(0.0,1.0); } } } //std::cerr << std::endl; glPopMatrix(); glPopAttrib(); // mShader.disable(); }