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

这篇博客介绍了两种在VTK中生成随机数的方法:一是利用vtkMath从平均值0.0和标准偏差2.0的高斯分布中获取随机数;二是使用vtkMinimalStandardRandomSequence作为随机序列生成器。
摘要由CSDN通过智能技术生成

方法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->G
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值