YETI
YETI

Reputation: 938

opencv RNG alternative for Java

I use opencv-3.2.0, I found RNG can use with C++, but not exist in Java:

C++

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

Java

There is no RNG

Please tell me how to use RNG uniform in Java.

Upvotes: 0

Views: 476

Answers (1)

smttsp
smttsp

Reputation: 4191

Just a small search on google, I found this link, in the explanation of uniform, it says:

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) .

And the examples:

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);

So, it seems java also have RNG.

Upvotes: 1

Related Questions