Solved

Implementation of Mersenne Twister in Java

Posted on 2006-07-06
6
774 Views
Last Modified: 2013-11-23
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
Comment
Question by:smik011
  • 3
  • 2
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17050980
You need to import

net.goui.util.MTRandom
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17050986
If you delete

package net.goui.util;

(not recommended) then you can use it without import if in classpath
0
 
LVL 13

Accepted Solution

by:
Webstorm earned 250 total points
ID: 17051805
You can do :

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

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 13

Expert Comment

by:Webstorm
ID: 17051828
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
 
LVL 92

Expert Comment

by:objects
ID: 17055030
following gives example of generating random numbers

http://javaalmanac.com/egs/java.util/GenRandom.html
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17064215
>>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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mergeTwo  challenge 13 72
mapBully challenge 6 93
Java Jpanels and Jframe 8 21
Cipher Configuration on Apache HTTPD 4 24
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now