本文整理汇总了C++中Rand::nextGaussian方法的典型用法代码示例。如果您正苦于以下问题:C++ Rand::nextGaussian方法的具体用法?C++ Rand::nextGaussian怎么用?C++ Rand::nextGaussian使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rand
的用法示例。
在下文中一共展示了Rand::nextGaussian方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Rectf
void Gaussian2App::draw()
{
gl::enableAlphaBlending();
//create an alpha blended background
gl::color( 0.0f, 0.0f, 0.0f, 0.01f );
gl::drawSolidRect( Rectf( 0, 0, mWidth, mHeight ) );
//get 3 gaussian random numbers w/ mean of 0 and standard deviation of 1.0
float r = (float) mGenerator->nextGaussian();
float g = (float) mGenerator->nextGaussian();
float b = (float) mGenerator->nextGaussian();
//define standard deviation and mean
float sd = 100.0f; float mean = 100.0f;
//scale by standard deviation and mean
//also constrain to between (0,255) since we are dealing with color
r = constrain( ( r * sd ) + mean, 0.0f, 255.0f );
//repeat for g & b
sd = 20; mean = 200;
g = constrain( ( g * sd ) + mean, 0.0f, 255.0f );
sd = 50; mean = 0;
b = constrain( ( b * sd ) + mean, 0.0f, 255.0f );
//get more gaussian numbers, this time for location
float xloc = (float) mGenerator->nextGaussian();
float yloc = (float) mGenerator->nextGaussian();
sd = mWidth/10;
mean = mWidth/2;
xloc = ( xloc * sd ) + mean;
yloc = ( yloc * sd ) + mean;
//draw an ellipse with gaussian generated color and location
gl::color( r, g, b );
gl::drawSolidEllipse( Vec2f( xloc, yloc ), 4.0f, 4.0f );
}
示例2:
void Example4App::update()
{
float num = generator_.nextGaussian();
xPos_ = sd_ * num + mean_;
}