unsigned Random::Poisson( double ExpectedValue ) { double Limit = exp( -ExpectedValue ); double Product = RandomReal( ); int Count; for( Count = 0; Product > Limit; Count++ ) Product *= RandomReal( ); return Count; }
void CannonSmokeParticleSystem::ResetParticle(Particle *particleToUpdate) { Vector3 particleVelocity; if(smokeDirection == Left) { particleVelocity = Vector3((-5.0f - emitterSpeed.x), (RandomReal(1.0f,1.5f) + (emitterSpeed.y/2.0f)),0.0f); } else if (smokeDirection == Right) { particleVelocity = Vector3((5.0f + emitterSpeed.x), (RandomReal(1.0f,1.5f) + (emitterSpeed.y/2.0f)),0.0f); } particleToUpdate->SetPosition(emetterLocation); particleToUpdate->SetVelocity(particleVelocity); particleToUpdate->ParticleReset(); }
/*----------------------------* * Function uniform (0, 1) | *----------------------------* | Get a random number between 0 and 1 */ double rnd() { double value=0.0, RandomReal(double, double); do value=RandomReal(0.0, 1.0); while((value==0.0)||(value==1.0)); return value; }
double init( double & pos, double & dir ) { pos = 0.0; if( RandomReal() < 0.5 ) { dir = 1.0; } else { dir = -1.0; } return 1.0; }
Particle *CannonSmokeParticleSystem::GenerateNewParticle() { SDL_Color particleColor= {255,255,255}; Vector3 particleVelocity; if(smokeDirection == Left) { particleVelocity = Vector3((-5.0f + emitterSpeed.x), (RandomReal(1.0f,2.0f) + (emitterSpeed.y/2.0f)),0.0f); } else if (smokeDirection == Right) { particleVelocity = Vector3((5.0f + emitterSpeed.x), (RandomReal(1.0f,2.0f) + (emitterSpeed.y/2.0f)),0.0f); } int RandomTextureIndex = rand() % (textureCount); #ifdef DEBUG_MODE printf("EmitterLocation X:%f, Y:%f\n", emetterLocation.x, emetterLocation.y); #endif Particle *returnParticle = new Particle (textures[RandomTextureIndex], emetterLocation, particleVelocity,//Vector3(1.0f * (float)(rand()*2.0f-1.0f),1.0f * (float)(rand()*2.0f-1.0f),0.0f), 0.0f, RandomReal(1.0f,2.0f), particleColor, RandomReal(0.25f,0.5f), (rand()%40+1), 45 ); ResetParticle(returnParticle); return (returnParticle); }
/** Move: tweaks the parameter-to-be-tweaked according to the current * value of index; also calls UpdateControl if necessary */ void Move( Files * files, DistParms * DistP ) { double tweakee; double theta; double sign; /* update counters */ idx++; nhits++; idx = idx % nparams; #ifdef MPI nsweeps = ( nhits / nparams ) * nnodes; #else nsweeps = ( nhits / nparams ); #endif /* update statistics if interval passed & at least one sweep completed */ if( !( nsweeps % ap.interval ) && !( idx ) && ( nsweeps ) ) { UpdateControl( files ); /* see comments in moves.h */ } //printf("idx=%d param=%lg lower=%lg upper=%lg\n", idx, *(ptab[idx].param), ptab[idx].param_range->lower, ptab[idx].param_range->upper); tweakee = *( ptab[idx].param ); pretweak = tweakee; /* this section does the tweaking */ theta = generate_dev( acc_tab[idx].theta_bar, DistP ); /* the sign stuff is needed for exponential distribution because always positive */ /* may (but not likely) need in future if wish to evaluate poisson or pareto distributions for fly */ if( DistP->distribution == 1 ) { /* need positive + negative values for theta */ sign = RandomReal( ) - 0.5; if( sign <= 0 ) theta = -theta; } //printf("idx %d theta %lg\n", idx, theta); tweakee += theta; *( ptab[idx].param ) = tweakee; /* original eqparms in score.c tweaked */ //printf("param = %lg\n", tweakee); }
bool RandomChance(double p) { return (RandomReal(0, 1) < p); }
double samplestep() { return -log( RandomReal() ) / mu_t; } // exponential sampling
double sampledir( const double prevDir ) // isotropic scattering { if( RandomReal() > 0.5 ) {return 1.0;} else {return -1.0;}; }
bool RandomChance(double probability) { return (RandomReal(0,1) < probability); }
double Random::NegExp( double ExpectedValue ) { return - ExpectedValue * log( RandomReal( ) ); }