[Solved] Mersenne Twister, and importing Java class

edited November 2013 in How To...

Hey guys, I am trying to find an implementation of the Mersenne Twister algorithm in Processing. I found this site: http://wiki.processing.org/w/Mersenne_Twister

but the project appears to be dead.

I found the original source for the project here: http://www.cs.gmu.edu/~sean/research/mersenne/MersenneTwisterFast.java

I am wondering if there is a way for me to load the java class into processing.

Any help would be appreciated.

~Ben

Answers

  • Answer ✓

    Just paste the .java file in the sketch, it will appear as a tab in Processing.

    You have to remove any package definition that can be at the top of the file.

  • I pasted the .java file in, and even after changing the classes from private to public, it is still failing to run. The error is:

    Usage: PApplet For additional options, see the Javadoc for PApplet Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and Help ? Troubleshooting.

    This might not be the best way to do this project.

  • Of course, you need to have a .pde file too, with the setup() and (optionally) draw() methods, that creates an instance of the class in the .java file and uses it...

  • I should have mentioned that I did all that, let me try with a bare minimum sketch.

    Ok, so I just figured it out:

    You need to have one class per file, and the filename needs to be the same as the class name, Then you can get an instance in a sketch like this:

    myClass MC1 = new myClass.someInitFunction(); myClass MC2 = new myClass.someInitFunction();

    and then you can use them

    print(MC1.mySuperAwesomeFunction());

    Also, in my instance I had to change all the private declarations (?) to public for it to compile.

  • edited November 2013

    I just put the finished library up on github, with an example:

    https://github.com/WildDoogyPlumb/Mersenne-Twister/tree/master/MTTest

Sign In or Register to comment.