VTK—— 生成 “随机数” 示例

方法1.

vtkMath,从平均0.0和标准偏差2.0的高斯分布中产生了3个随机数

#include 
#include 
#include 

int main(int, char *[])
{
    unsigned int numRand = 3;
    vtkMath::RandomSeed(time(nullptr));
    for (unsigned int i = 0; i < numRand; ++i)
    {
        double num = vtkMath::Gaussian(0.0, 2.0);
        qDebug() << "num : " << num;
    }
    
    return EXIT_SUCCESS;
}

 

方法2.

vtkMinimalStandardRandomSequence,它实际上是一个随机序列生成器

#include 
#include 
#include 

int main(int, char *[])
{
    vtkSmartPointer sequence = vtkSmartPointer::New();
    
    sequence->SetSeed(1);

    double x = sequence->GetValue();
    sequence->Next();
    double y = sequence->GetValue();
    sequence->Next();
    double z = sequence->GetValue();
    
    qDebug() << "x: " << x << " ,y: " << y << " ,z: " << z;

    return EXIT_SUCCESS;
}

 

你可能感兴趣的:(VTK)