• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 826
  • Last Modified:

Implementation of Mersenne Twister in Java

I'm having a few problems actually generating random numbers using a Java implementation of the Mersenne Twister Random Number Generator from (http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/JAVA/MTRandom.java). I've only had 1 years wort of experience in Java so you might understand the problem. What I want to be able to do is actually generate a random number for my project comparing different Random Number Generators. For example, to generate a random number using Math.random( ) you would simply do the following:

double myVar = Math.random( );

Now, how would you do the same for the Mersenne Twister java implementation listed above? do I need to import anything?

A worked out example in Java would be greatly appreciated.

0
smik011
Asked:
smik011
  • 3
  • 2
1 Solution
 
CEHJCommented:
You need to import

net.goui.util.MTRandom
0
 
CEHJCommented:
If you delete

package net.goui.util;

(not recommended) then you can use it without import if in classpath
0
 
WebstormCommented:
You can do :

java.util.Random r=new net.goui.util.MTRandom();
double myValue = r.nextDouble();

0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
WebstormCommented:
Also MTRandom.java need to be in net/goui/util directory (create it)
then you must specify the directory where you put the "net" directory in the class path :

javac -cp .;C:\mylib MyClass.java
java -cp .;C:\mylib MyClass

if you have C:\mylib\net\goui\util\MTRandom.java
0
 
objectsCommented:
following gives example of generating random numbers

http://javaalmanac.com/egs/java.util/GenRandom.html
0
 
CEHJCommented:
>>java.util.Random r=new net.goui.util.MTRandom();

That's not a good idea. You should be able to see which classes are used in a source file, not by reading it all, but by reading the imports at the top of the file
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now