gpt4 book ai didi

java - Java 的 opencv RNG 替代方案

转载 作者:行者123 更新时间:2023-12-02 13:41:14 24 4
gpt4 key购买 nike

我使用opencv-3.2.0,我发现RNG可以与C++一起使用,但在Java中不存在:

C++

RNG rng( 0xFFFFFFFF );
rng.uniform( -3, 10 );
rng.uniform(0, 200);

Java

There is no RNG

请告诉我如何在Java中使用RNG制服。

最佳答案

只需在 google 上进行少量搜索,我就找到了这个 link ,在uniform的解释中,它说:

returns uniformly distributed integer random number from [a,b) range. The methods transform the state using the MWC algorithm and return the next uniformly-distributed random number of the specified type, deduced from the input parameter type, from the range [a, b) .

以及示例:

RNG rng;

// always produces 0
double a = rng.uniform(0, 1);

// produces double from [0, 1)
double a1 = rng.uniform((double)0, (double)1);

// produces float from [0, 1)
double b = rng.uniform(0.f, 1.f);

// produces double from [0, 1)
double c = rng.uniform(0., 1.);

// may cause compiler error because of ambiguity:
// RNG::uniform(0, (int)0.999999)? or RNG::uniform((double)0, 0.99999)?
double d = rng.uniform(0, 0.999999);

所以,看来java也有RNG

关于java - Java 的 opencv RNG 替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42735869/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com