---
title: 拷贝随机数流函数
description: "拷贝随机数流stream。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0491.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0491.html
indexId: 62ff40f9f6bfe496e2d5ad7735748823c31122b3cdea774e63530457054e319b61
---
# 拷贝随机数流函数

拷贝随机数流stream。

#### 接口定义

int vslCopyStream(VSLStreamStatePtr *newStream, VSLStreamStatePtr stream);


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| newStream | VSLStreamStatePtr类型 | 新随机数流。 | 输出 |
| stream | VSLStreamStatePtr类型指针 | 指向被拷贝随机数流结构体的指针。 | 输入 |


#### 依赖

#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;
}
VSLStreamStatePtr stream2;
if (vslCopyStream(&stream2, stream)) {
fprintf(stderr, "Failure in vslCopyStream\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;
}
```
