Results 1 to 7 of 7
  1. #1
    mental is offline Member
    Join Date
    Mar 2010
    Posts
    2
    Rep Power
    0

    Default Mersenne twister random generator

    Hey, I found a mersenne twister algorithm but I have no idea who to use it in my program to generate a number from 0-100.

    Is it used like the default java generator of java?
    Like:

    public static int RandomIntNumber() {
    Random gen = new Random();
    return (gen.nextInt(100);
    }

    I dont mind using xorshift generator as well.

    Thanks in advance.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Much better,

    Java Code:
    Random random = new Random();
    int randomInt = random.nextInt(100);

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,365
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Eranga View Post
    Additionally you can use the Math class as well. Try Math.random()
    For some real random numbers (no pseudo random numbers) have a look at this link.

    kind regards,

    Jos

  5. #5
    mental is offline Member
    Join Date
    Mar 2010
    Posts
    2
    Rep Power
    0

    Default

    maybe I wasnt too clear. I got the MersenneTwister.java from here Sean Luke : Code and I have it in the folder or my program. Does it replace the random class and all I have to do is create a random object like a I would with the default random method or is there different way?

    Also I wouldnt mind using an xorshift generator if one can provide an algorithm for the job I need it for.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by JosAH View Post
    For some real random numbers (no pseudo random numbers) have a look at this link.
    Hmm, I've never stuck on that before. Since it generate random number (as you outline pseudorandom) and the method is fully synchronized no matter at all.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by mental View Post
    maybe I wasnt too clear. I got the MersenneTwister.java from here Sean Luke : Code and I have it in the folder or my program. Does it replace the random class and all I have to do is create a random object like a I would with the default random method or is there different way?
    Not clear to me now, that what you exactly want to do with the code. Do you want to generate random class names in your code? What the usage of that, can you please clear-up bit more?

Similar Threads

  1. My blackjack games random generator doesnt work!
    By Addez in forum New To Java
    Replies: 16
    Last Post: 08-17-2009, 05:29 AM
  2. Help with class project, random number generator.
    By Christopher The Great in forum New To Java
    Replies: 4
    Last Post: 03-14-2009, 02:12 AM
  3. Random Shape generator
    By scheng12 in forum New To Java
    Replies: 1
    Last Post: 03-09-2009, 02:06 AM
  4. Replies: 3
    Last Post: 05-27-2008, 01:51 PM
  5. Random Generator
    By padutch2 in forum New To Java
    Replies: 1
    Last Post: 12-03-2007, 06:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •