Skip to content

获取随机整数 - GetRandomNumber

函数简介

获取指定范围内的随机整数,使用线程独立的随机种子,确保多线程环境下的随机性。

接口名称

GetRandomNumber

DLL调用

c
int GetRandomNumber(long instance, int min, int max);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
min整数型随机数的最小值(包含)。
max整数型随机数的最大值(包含)。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int n = ola.GetRandomNumber(1, 100);
csharp
using OLAPlug;

var ola = new OLAPlugServer();
int n = ola.GetRandomNumber(1, 100);
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
n = ola.GetRandomNumber(1, 100)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
int n = ola.GetRandomNumber(1, 100);
cpp
var ola = com("OlaPlug.OlaSoft")
var n = ola.GetRandomNumber(1, 100)
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
n = ola.GetRandomNumber(1, 100)
text
.局部变量 ola, OLAPlug
ola.创建 ()
n = ola.GetRandomNumber (1, 100)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var n = ola.GetRandomNumber(1, 100);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 n = ola.GetRandomNumber(1, 100)
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int32_t n = ola.GetRandomNumber(1, 100);

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
int n = GetRandomNumber(1, 100);
csharp
using System.Runtime.InteropServices;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();

long instance = CreateCOLAPlugInterFace();
int n = GetRandomNumber(1, 100);
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
n = ola.GetRandomNumber(1, 100)

返回值

返回值说明
(返回值)返回指定范围内的随机整数(整数型)。

注意事项

项目说明
随机数包含最小值和最大值返回的随机数包含最小值和最大值。
每个线程使用独立的随机种子每个线程使用独立的随机种子,确保多线程环境下的随机性。