Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RNG issue #276

Closed
mertus opened this issue Dec 1, 2016 · 1 comment
Closed

RNG issue #276

mertus opened this issue Dec 1, 2016 · 1 comment
Labels
bug Something isn't working

Comments

@mertus
Copy link

mertus commented Dec 1, 2016

I'm using VS2013, 64 bit and Nuget release with my opencv_world310.dll
If I do

        var r = new OpenCvSharp.RNG(1234);
        var r1 = r.Uniform(0, 10);
        var r2 = r.Uniform(0, 10);
        var r3 = r.Uniform(0, 10);

I get r1 == r2 == r3 == 4

But if I use the c-code, using the same opencv_world310.dll

		auto r = new cv::RNG(1234);
		auto r1 = r->uniform(0, 10);
		auto r2 = r->uniform(0, 10);
		auto r3 = r->uniform(0, 10);

I get r1 == 4, r2 == 6, r3 == 9

However, randu behaves correctly in C# and C++

More information. The State value of RNG in C# never changes from the seed 1234 while in the C++ code it changes.

So I looked at your code. The issue appears to be, for example, RNG.schar call core_RNG_operator_schar passing a state variable but that is not by reference anywhere. Thus the state never changes. I think if you just put in ref it would work. I don't know very much about OpenCV but there appears maybe an efficiency issue. Each time you do a RNG.uniform etc, you recreate a c++ RNG with that seed. I don't know the cost of that but it could be much more expensive than the Multiply with Carry of a single random generator.

That said, I really don't care about efficiency! Thanks for all your work

@shimat shimat added the bug Something isn't working label Dec 3, 2016
@shimat shimat closed this as completed in 733e5e5 Dec 4, 2016
@shimat
Copy link
Owner

shimat commented Dec 4, 2016

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants