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

方法1.

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

#include <vtkMath.h>
#include <time.h>
#include <QDebug>

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 <vtkSmartPointer.h>
#include <vtkMinimalStandardRandomSequence.h>
#include <QDebug>

int main(int, char *[])
{
    vtkSmartPointer<vtkMinimalStandardRandomSequence> sequence = vtkSmartPointer<vtkMinimalStandardRandomSequence>::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;
}

猜你喜欢

转载自blog.csdn.net/Jecklin_online/article/details/83184783
今日推荐