本文整理汇总了C++中randf函数的典型用法代码示例。如果您正苦于以下问题:C++ randf函数的具体用法?C++ randf怎么用?C++ randf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了randf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: display
static void display(void)
{
glClearColor(randf(), randf(), randf(), 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
glutPostRedisplay();
}
开发者ID:rmuenste,项目名称:opengl-sdl,代码行数:7,代码来源:test.c
示例2: randMat
glm::mat4 randMat()
{
float theta = randf(-PI / 2, PI / 2), phi = randf(0.0f, 2 * PI);
glm::mat4 rotation = glm::rotate(glm::mat4(1.0), phi, glm::vec3(1.0, 0.0, 0.0));
rotation = glm::rotate(rotation, theta, glm::vec3(0.0, 1.0, 0.0));
return rotation;
}
开发者ID:davidwalton3142,项目名称:fire-framework,代码行数:7,代码来源:LightDemo.cpp
示例3: randf
void Server::broadcastFaultyData(const char* data, unsigned int size) {
packetNumber++;
// lose messages every so often
if (randf() * 100 < m_packetlossPercentage)
return;
// delay messages every so often
if (randf() * 100 < m_delayPercentage) {
DelayedBroadcast* b = new DelayedBroadcast;
b->stream.Write((RakNet::MessageID)GameMessages::ID_ENTITY_LIST);
b->stream.Write(size);
b->stream.Write(packetNumber);
b->stream.Write(data, size);
float delay = randf() * m_delayRange;
b->delayMicroseconds = (double)(delay * 1000.0 * 1000.0);
m_delayedMessages.push_back(b);
}
else {
// just send the stream
RakNet::BitStream stream;
stream.Write((RakNet::MessageID)GameMessages::ID_ENTITY_LIST);
stream.Write(size);
stream.Write(packetNumber);
stream.Write(data, size);
sendBitStream(&stream);
}
}
开发者ID:BenjaminMatthewMoore,项目名称:NetworkAssignment,代码行数:27,代码来源:Server.cpp
示例4: float
void FlowShower::update()
{
scale += (scaleb - scale) * 0.1;
if (game->isMiddleDown() && !painting)
{
viewX = pressViewX + (pressX - float(game->getMouseX())
/ float(game->getResY())) / scale;
viewY = pressViewY - (pressY - float(game->getMouseY())
/ float(game->getResY())) / scale;
}
inkNew+=0.1f;
while(inkNew>=1.0f)
{
inkNew-=1.0f;
inkRed=inkRedNew;
inkGreen=inkGreenNew;
inkBlue=inkBlueNew;
inkRedNew=randf(1.0f);
inkGreenNew=randf(1.0f);
inkBlueNew=randf(1.0f);
}
clock_t curentClock = clock();
/*if (lastClock != 0 || dt != 0)
dt = float(curentClock - lastClock) / 1000.0f;*/
lastClock = curentClock;
}
开发者ID:kpws,项目名称:Flower,代码行数:27,代码来源:FlowShower.cpp
示例5: srand
void Tile::Init(float roughness) {
// Zufallsgenerator initialisieren
srand(static_cast<unsigned int>(time(0)));
// x- und z-Koordinaten berechnen.
// Das Wurzel-Tile ersteckt sich entlang der x- und z-Achse immer im Bereich
// [-2.5, 2.5]
int i = 0;
for (int y = 0; y < size_; ++y) {
for (int x = 0; x < size_; ++x, ++i) {
vertices_[i].x = x * 5.0f / (size_ - 1) - 2.5f;
vertices_[i].z = y * 5.0f / (size_ - 1) - 2.5f;
}
}
// Ecken mit Zufallshöhenwerten initialisieren
int block_size = size_ - 1;
vertices_[I(0, 0)].y = randf();
vertices_[I(0, block_size)].y = randf();
vertices_[I(block_size, 0)].y = randf();
vertices_[I(block_size, block_size)].y = randf();
// Verfeinerungsschritte durchführen bis sämtliche Werte berechnet sind
while (block_size > 1) {
Refine(block_size, roughness);
block_size = block_size / 2;
}
}
开发者ID:reima,项目名称:sep3d,代码行数:28,代码来源:Tile.cpp
示例6: RandFloat
static inline float RandFloat(const float min, const float max) {
// we work with large floats here (1e22 etc.) we cannot blend them without overflows, so do it a bit differently
if (rand() & 1) {
return max * randf();
}
return min * randf();
}
开发者ID:DoctorEmmettBrown,项目名称:spring,代码行数:7,代码来源:testPrintf.cpp
示例7: metro
void metro(double *m, double *T) /*Metropolitan algorithm*/
{
int i, x, y, xdown, xup, ydown, yup, sum;
double deltaE;
for (i = 0; i < LX*LY; i++)
{
x = randf()*LX; /* Choose a random coordinate in the lattice */
y = randf()*LY;
xup = (x + 1)%LX; /*determine neighbor sites, with periodic BCs */
xdown = (x + LX - 1)%LX;
yup = (y + 1)%LY;
ydown = (y + LY - 1)%LY;
/*compute the sum of the spins of sites neighboring coordinate*/
sum = spin[xdown][y] + spin[xup][y] + spin[x][yup] + spin[x][ydown];
/*compute change in energy if spin is flipped at coordinate*/
deltaE = 2.0*J*spin[x][y]*sum/(*T);
if (randf() < exp(-deltaE)) /* decide if flip is accepted*/
{
*m -= 2.0*spin[x][y]/(LX*LY); /*flip spin and compute m*/
spin[x][y] *= -1;
}
}
}
开发者ID:nosubsgo,项目名称:numericalmethods,代码行数:27,代码来源:ising2d.c
示例8: generateRandomPyrFrustums
void generateRandomPyrFrustums( int n,
float minFOV, float maxFOV,
float minNear, float maxNear,
float minFar, float maxFar,
float minAspectRatio, float maxAspectRatio,
float minPosX, float maxPosX,
float minPosY, float maxPosY,
float minPosZ, float maxPosZ,
float minRotX, float maxRotX,
float minRotY, float maxRotY,
float minRotZ, float maxRotZ,
std::vector<glPyramidalFrustum>& list )
{
for(int i = 0; i < n; ++i )
{
float FOV = minFOV + randf()*( maxFOV - minFOV );
float Near = minNear + randf()*( maxNear - minNear );
float Far = minFar + randf()*( maxFar - minFar );
float AspectRatio = minAspectRatio + randf()*( maxAspectRatio - minAspectRatio );
float PosX = minPosX + randf()*( maxPosX - minPosX );
float PosY = minPosY + randf()*( maxPosY - minPosY );
float PosZ = minPosZ + randf()*( maxPosZ - minPosZ );
float RotX = minRotX + randf()*( maxRotX - minRotX );
float RotY = minRotY + randf()*( maxRotY - minRotY );
float RotZ = minRotZ + randf()*( maxRotZ - minRotZ );
glPyramidalFrustum f(FOV, Near, Far, AspectRatio, glVector4f(PosX, PosY, PosZ, 0), RotX, RotY, RotZ );
list.push_back( f );
}
}
开发者ID:Buanderie,项目名称:gpufrustum,代码行数:29,代码来源:utils.cpp
示例9: cart_rnd_star
void cart_rnd_star(int id)
{
float x = randf(2.0)-1.0;
float y = randf(2.0)-1.0;
stars[id][0] = sqrtf(x*x+y*y);
stars[id][1] = atan2(y,x);
}
开发者ID:marcan,项目名称:openlase,代码行数:7,代码来源:demo.c
示例10: SPIN_SPEED
PowerUp::PowerUp(float x, float y, int type) :
SPIN_SPEED(0.002f)
{
this->x = x;
this->y = y;
this->type = type;
dx = randf(0.5f, 1.2f);
dy = randf(0.5f, 1.2f);
radius = 16;
isDestructable = false;
hp = 1;
da = (rand() % 2) ? -SPIN_SPEED : SPIN_SPEED;
ResourceManager& rm = ResourceManager::getInstance();
switch (type) {
case POWERUP_LIFE:
bitmap = (ALLEGRO_BITMAP *)rm.getData(RES_LIFEPOWERUP);
break;
default:
type = POWERUP_WEAPON;
bitmap = (ALLEGRO_BITMAP *)rm.getData(RES_WEAPONPOWERUP);
break;
}
}
开发者ID:dradtke,项目名称:battlechess,代码行数:27,代码来源:PowerUp.cpp
示例11: updateGrainPosition
//get trigger position/volume relative to sound rects for single grain voice
void GrainClusterVis::getTriggerPos(unsigned int idx, double * playPos, double * playVol,float theDur)
{
bool trigger = false;
SoundRect * theRect = NULL;
if (idx < myGrainsV->size()){
GrainVis * theGrain = myGrainsV->at(idx);
//TODO: motion models
//updateGrainPosition(idx,gcX + randf()*50.0 + randf()*(-50.0),gcY + randf()*50.0 + randf()*(-50.0));
updateGrainPosition(idx,gcX + (randf()*xRandExtent - randf()*xRandExtent),gcY + (randf()*yRandExtent - randf()*yRandExtent));
for (int i = 0; i < theLandscape->size(); i++) {
theRect = theLandscape->at(i);
bool tempTrig = false;
tempTrig = theRect->getNormedPosition(playPos,playVol,theGrain->getX(),theGrain->getY(),i);
if (tempTrig == true)
trigger = true;
// cout << "playvol: " << *playPos << ", playpos: " << *playVol << endl;
}
if (trigger == true){
theGrain->trigger(theDur);
}
}
}
开发者ID:hangtwenty,项目名称:borderlands-granular-pitch-patch,代码行数:26,代码来源:GrainCluster.cpp
示例12: setup
void setup(){
map.init( 16, 14, 0.2 );
printf( " %f \n", map.invStep );
/*
Point2D* p = new Point2D( { 10.8, 13.9 } );
printf( " p: %f %f \n",p->x,p->y );
int ix,iy;
map.boxIndex( p, ix, iy );
printf( " ix,iy: %i %i \n",ix,iy );
*/
for (int i=0; i<1000; i++){
Point2D* p = new Point2D( { randf(0,2), randf(0,2) } );
map.insert( p );
//printf( " i:i0,ii,i0s[ii] %i: %i %i %i \n", i, i0, ii, map.i0s[ii] );
};
map.makeStatic();
}
开发者ID:ProkopHapala,项目名称:cpp_arch,代码行数:25,代码来源:main.cpp
示例13: AppSDL2OGL
TestApp::TestApp( int& id, int WIDTH_, int HEIGHT_ ) : AppSDL2OGL( id, WIDTH_, HEIGHT_ ) {
//int power = 8; int nside = 5;
//int power = 11; int nside = 20;
int power = 16; int nside = 300;
//int power = 20; int nside = 400;
//int power = 24; int nside = 1500;
npoints = 4*nside*nside;
points = new Vec2d[npoints];
map.init( 0.5f, power );
printf( "map: %i %i %i %i \n", map.power, map.mask, map.capacity, map.filled );
int i = 0;
for( int iy=-nside+1; iy<nside; iy++ ){
for( int ix=-nside+1; ix<nside; ix++ ){
i++;
points[ i ].set( ( ix + randf() ) * map.step, ( iy + randf() ) * map.step );
//map.insertNoTest( &(points[i]), points[i].x, points[i].y );
map.insertIfNew( &(points[i]), points[i].x, points[i].y );
//printf( " insering (%i,%i) %i (%3.3f,%3.3f) \n", ix, iy, i, points[i].x, points[i].y );
};
};
printf( "map: %i %i %i %i \n", map.power, map.mask, map.capacity, map.filled );
hist.init( 20, 0, 20 );
for( int i=0; i<map.capacity; i++ ){
hist.insert( map.fields[i].n + 0.5 );
}
printf( "now comes printHistogram( hist );\n" );
printHistogram( hist );
}
开发者ID:ProkopHapala,项目名称:SimpleSimulationEngine,代码行数:32,代码来源:test_HashMap2D_uniformity.cpp
示例14: random_points
void random_points(point ps[], int count, double min, double max, bool integer)
{
std::set<std::pair<int, int>> points_set;
if (integer)
{
for (int i = 0; i < count; i++)
{
bool unique = true;
int x, y;
do
{
x = (int)round(min + (max - min) * randf());
y = (int)round(min + (max - min) * randf());
if (points_set.find(std::make_pair(x, y)) != points_set.end())
unique = false;
} while (!unique);
ps[i] = point(x, y);
points_set.insert(std::make_pair(x, y));
}
}
else
{
for (int i = 0; i < count; i++)
ps[i] = point(min + (max - min) * randf(), min + (max - min) * randf());
}
}
开发者ID:BichengLUO,项目名称:random_room,代码行数:26,代码来源:main.cpp
示例15: srand
Path SplineGenerator::makeBezier(int points, int nodes, int seed)
{
srand(seed);
Path path;
int minDist = 0.35355;
std::cout << "MinDist: " << minDist << std::endl;
Vector2d start(randf(),0);
Vector2d end(randf(),1);
for (int node=0 ; node < nodes ; ++node)
{
Vector2d p0 = start;
Vector2d p1(randf(), randf());
// Vector2d p1(rand()%w,rand()%h);
Vector2d p2(randf(), randf());
Vector2d p3(randf(), randf());
while(p3.getDistance(p1)<minDist)
{
p3.x = randf();
p3.y = randf();
}
int pointsPerNode = points / nodes;
for (int x=0; x<pointsPerNode;++x)
{
float t = x/float(pointsPerNode);
Vector2d res= calculateBezierPoint(t,p0,p1,p2,p3);
path.push_back(res);
}
start = p3;
}
//do last link
// Vector2d p0 = start;
// Vector2d p1(rand()%w,rand()%h);
// Vector2d p2(rand()%w,rand()%h);
// Vector2d p3 = end;
// for (int x=0; x<steps;++x)
// {
// float t = x/float(steps);
// Vector2d res= calculateBezierPoint(t,p0,p1,p2,p3);
// if (x!=0)
// {
// out << t << "\t" << res.x <<"\t" << res.y << std::endl;
// }
// else
// {
// out << t << "\t" << res.x <<"\t" << res.y << "\t" << start.x << "\t" << start.y << std::endl;
// }
// }
//end test for bezier curving
return path;
}
开发者ID:samhaldenby,项目名称:NewComponentEngine,代码行数:59,代码来源:SplineGenerator.cpp
示例16: startup_scene
static void startup_scene()
{
// generate random starfield
for ( int i=0; i < NUM_STARS; ++i )
{
star[i] = vec( randf(), randf(), randf() ).unit() * 2.0f;
}
}
开发者ID:morankim,项目名称:midtermProject,代码行数:8,代码来源:sample.cpp
示例17: shake
void shake(void)
{
shakeUpdateCount = SHAKE_TIME;
bgx = randf(0.0f, 8.0f);
bgy = randf(0.0f, 8.0f);
if (rand() % 2) bgx = -bgx;
if (rand() % 2) bgy = -bgy;
}
开发者ID:EricMayberryIV,项目名称:COP3330-Introduction-to-OOP,代码行数:8,代码来源:render.cpp
示例18: spawn
glm::vec3 spawn() {
glm::vec3 cand;
do {
cand = glm::vec3(randf(-10.0f, 10.0f), 2.0f, randf(-10.0f, 10.0f));
} while (glm::length(circleCollision(cand, MINE_RADIUS, 4, true, true)) > 0.0f);
return cand;
}
开发者ID:Mimoja,项目名称:HookWars,代码行数:8,代码来源:Mine.cpp
示例19: collision
void collision(vector2f & vel,double&omega,double theta)
{
double alpha=randf();
double beta=randf()*M_PI;
double v=water.mk().abs();
omega+=12*(alpha-0.5)*v*beta/1000;
vel+=v*cos(beta)/1000000*vector2f(cos(theta),sin(theta));
}
开发者ID:xuhao1,项目名称:Rand_Walk,代码行数:8,代码来源:namibang.cpp
示例20: createRandomSynapseGene
Gene Gene::createRandomSynapseGene(int nNeurons) {
GeneSynapse g;
g.from.set(randi(nNeurons-1));
g.to.set(randi(nNeurons-1));
g.weight.set(randf()*0.2f);
g.priority.set(randf()*10);
return g;
}
开发者ID:bog2k3,项目名称:bugs,代码行数:8,代码来源:Gene.cpp
注:本文中的randf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论