创建随机数流函数
初始化stream结构体并设置随机数种子。
接口定义
int vslNewStream(VSLStreamStatePtr *stream, const int brng, const unsigned seed);
参数
参数名 |
类型 |
描述 |
输入/输出 |
|---|---|---|---|
stream, |
VSLStreamStatePtr类型指针 |
指向随机数流结构体的指针。 |
输出 |
brng |
int |
随机数生成器类型。
|
输入 |
seed |
unsigned |
随机数种子,为非负整数。 |
输入 |
依赖
#include "krng.h"
示例
#include <stdio.h>
#include <stdlib.h>
#include "krng.h"
int main()
{
/* initialize stream with given BRNG type and seed */
VSLStreamStatePtr stream;
unsigned seed = 42;
int errcode = vslNewStream(&stream, VSL_BRNG_MCG59, seed);
if (errcode != VSL_STATUS_OK) {
fprintf(stderr, "Failure in newstream\n");
return 0;
}
/* deinitialize the stream */
errcode = vslDeleteStream(&stream);
if (errcode != VSL_STATUS_OK) {
fprintf(stderr, "Failure in deleting stream\n");
return 0;
}
return 0;
}
父主题: 高性能函数