Returns random number?

Is there a code that simply returns a random number?

Math.random(); will give you a value between 0 and 1.
Could be multiplied with arbitrary number like (int)
5*Math.random();
which will give you either 0, 1 ,2, 3 or 4.Better to use java.util.Random.nextInt

Similar Messages

  • Make a variable return a random number?

    I need to know how to quickly make a variable return a random number, in PHP if i wanted a variable to return a random number it'd look like this using a built in function,
    (int)$my_variable = rand(0,10); // returns 0 through 10 randomly
    How can i do this with Java if say my variable looks like this.
    public Integer madeThisUp = 1; // Needs to be random 0-10 aswell..
    I can't find any tutorials on this that make clear sense to me, :-\

    2) java.util.Random has a bunch of methods that
    correspond directly to common uses of random numbers.
    I can't imagine a situation where Math.random would
    be easier to understand.case in point, when a method is provided for you but you
    try to reinvent it with:
    int i = (int) (Math.random() * 10);

  • Applescript: how to record and return how many times a number appears when using a random number generator

    I create one rng and repeat another rng that many times like so:
    set x to (random number from 0 to 250)
    repeat x times
      set rn to (random number from 1 to 10)
    end repeat
    now what i would like to do is record and return how many times 'rn' comes up with one particular number. Any ideas?

    You could set up a list and increment the contents of a particular index each time it comes up, for example:
    set how_many to {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -- 1 thru 10
    set x to (random number from 0 to 250)
    repeat x times
      set rn to (random number from 1 to 10)
      set item rn of how_many to (item rn of how_many) + 1
    end repeat
    return how_many

  • A simple question on random number generation?

    Hi,
    This is a rather simple question and shows my newbieness quite blatantly!
    I'm trying to generate a random number in a part of a test I have.
    So, I have a little method which looks like this:
    public int getRandomNumber(int number){
            Random random = new Random(number);
            return random.nextInt(number);
        }And in my code I do int random = getRandomNumber(blah)...where blah is always the same number.
    My problem is it always returns the same number. What am I missing here. I was under the impression that nextint(int n) was supposed to generate the number randomly!! Obviously I'm doing something wrong or not using the correct thing. Someone please point out my stupidity and point me in the right direction? Ta

    I think the idea is that Random will generate the same pseudo-random sequence over and over if you don't supply a seed value. (The better to debug with, my dear.) When you're ready to put an app into production, the seed value should be the current system time in milliseconds to guarantee a new sequence with each run.
    Do indeed move Random outside the loop. Think of it like a number factory - instantiate it once and let it pump out the random values for you as needed.

  • How do I assign images to grid cells based on their random number value?

    Hello everyone!
         I need a good point (or shove) in the correct direction.
    Background
         I've created (with previous help from this forum) a 12 x 9 random number grid which cycles through the numbers 1 to 9 a total of twelve times each. I've then created a button which shuffles the current grid's cells each time it is clicked. I now want to use 9 images that I have imported as individual symbols into the library (I have given them each their own class titled "skin1," "skin2," ... "skin9") as cell labels or the equivalent. I have also set the images up as individual movie clips (using the .Sprite class as the extended base class but keeping the actual image class names in line with their object name, i.e. the "skin1" image is the "skin1.as" class).
    Question
         How do I assign these images to the grid cells based on their respective values (ranging from 1 to 9) and have them populate the grid each time I click the "shuffle" button? So for example, in my grid the numbers 1 through 9 randomly appear 12 times each. Every time the number 4 appears in a cell, I want it to be assigned to the image "skin4" (which is just a graphic that looks like a button and has a fancy number "4" printed on it). Below is a chunk of the code I am using to draw the grid cells with:
    // Creates a grid cell when called by generateGrid().
    private funciton drawCell(_numeral:int):Sprite
              This is the code I am currently implementing to populate the grids with (although I
              don't want to use text labels as I want to fill each grid with an image according
              to its numerical value (1 to 9).
         var _label:TextField = new TextField();
         _label.multiline = _label.wordWrap = false;
         _label.autoSize = "center";
         _label.text = String(_numeral);
         // Add numerical label to cell array.
         cellLabels.push(_label);
         var _s:Sprite = new Sprite();
         _s.graphics.lineStyle(2, 0x019000);
         _s.graphics.drawRect(30, 0, cellW, CellH);
         _s.addChild(_label);
         return _s;
         While the following isn't working code, it will hopefully demonstrate what I want to achieve inside this function so I don't have to use the above snippet for text labels:
         //This will "hopefully" create an array of all 9 images by calling their classes.      var _imageArray:Array = [skin1, skin2, skin3, skin4, skin5 , skin6, skin7, skin8, skin9];      // This is what I want to happen for each cell using the above image array:      for (i = 0; i < cells; i++)      {           if (_numeral == 1)           {                // Insert skin1 image for each instance of #1 in the grid.           }           if (_numeral == 2)           {                // Insert skin2 image for each instance of #2 in the grid.           }           ...           if (_numeral == 9)           {                // Insert skin9 image for each instance of #9 in the grid.           }      } 
         Again, I don't want to use text labels. I have a custom skin graphic that I want to go over each number on the grid based on its numerical value (1 to 9). Any help with this is much appreciated!

    kglad,
         Thank you for your help with this one. Using the code below, I have successfully populated my grid cells with the desired corresponding graphics. I noticed one thing though regarding my use of the shuffle button with this particular implementation: even though the numerical values residing in each cell get shuffled, the original images remain in the grid rather than being replaced by new ones. The first code snippet below is the revised cell drawing function including your help; the second snippet shows you my simple shuffle button function (where the problem lies, I think).
    Snippet #1:
         // Creates a grid cell when called by generateGrid().
         private function drawCell(_numeral:int):Sprite
              var _label:TextField = new TextField();
              _label.multiline = _label.wordWrap = false;
              _label.autoSize = "center";
              // Creates a label that represents the numerical value of the cell.
              cellLabels.push(_label);
              var _s:Sprite = new Sprite();
              _s.graphics.lineStyle(2, 0x019000);
              _s.graphics.drawRect(30, 0, cellW, cellH);
              // Physically adds the labels to the grid.
              _s.addChild(_label);
              // Assigns a graphic class to a cell based on its numerical value.
              var _classRef:Class = Class(getDefinitionByName("skin" + _numeral));
              // Undefined variable for holding graphic classes.
              var _image:* = new _classRef();
              // Lines the images up with the grid cells.
              _image.x = 30;
              // Physically adds a graphic on top of a cell label.
              _s.addChild(_image);
              return _s;
         So far so good (although I question needing text labels at all if they are just going to remain invisible underneath the images, but enough about that for now). This next part is the reason that the images won't shuffle with the cell values, I think.
    Snippet #2:
         // When shuffleButton is clicked, this event shuffles
         // the number array and fills the cellLabels with the new values.
         private function onButtonShuffleClick(e:MouseEvent):void
              // Shuffles the number array.
              shuffle(numbers);
              // Verifies the array has been shuffled.
              trace("After shuffle:", numbers);
              // Loop replaces old cellLabels with new number array values.
              for (var i:int = 0; i < cells; i++)
                   cellLabels[i].text = String(numbers[i]);
         As you can see, it never replaces the original images that populate the grid. I tried using the _s.removeChild(image) function but that didn't work, nor would copying/pasting some of the code from snippet #1 directly into this function as it would cause another instance of the images to be placed over top of the existing ones rather than actually swapping them out. Any continued help here is greatly appreciated!
         PS Is there a quicker method for posting code into these forums without having to type it all out by hand again (i.e. copy/paste or drag/drop from my .fla or Notepad file directly into this thread)?

  • [JS CS3] Check the pattern of a random number given a specific data ?

    Hi all,
    I succeed getting a random number of this look : d.dd (8.73 for ex)
    I use Math.random()*(max-min)+min;
    I want to check that this number respect a specific given increment.
    To be clear :
    If I set min to 0 and max to 10 for example.
    The script returns a number like 8.56
    Now, I have a increment like 0.2
    I want the script to give me a number that can be d,d.2,d.4,d.6,d.8
    BUT NOT d.78 or d.1
    I guess I may use a while command but have no idea of the checking operation.
    Any idea ?
    Thanks in advance.
    Loic

    Math to the rescue. You want a random integer div 5.
    Math.floor(5*(Math.random()*(max-min)+min))/5 should do it.

  • Is there any way to generate random number in CPO

    Requirement : -
    > I want  to generate a random number from set of 1-9 numbers .is there any way in cpo ?
    Thanks
    Siva

    I created a process that uses 3 steps, all of which happen inside the engine rather than having to span out to a script, so it runs a lot faster.
    Technically, it's pseudo-random...
    Predefine Output Variable "Random Number" as type "Numeric"
    Step 1:  Format Date
      Format string: fffffff 
        (that's seven lower-case letters "f")
      Original date: [Process.Start Time]
    Step 2: Format Date
      Format string: ff\0\0\0\0\0
      Original date: [Process Start Time]
    Step 3: Set Variable
      Variable to update: [Process.Variables.Output.Random Number]
      New value: ([Workflow.Format Date.Formatted Date]-[Workflow.Format Date (2).Formatted Date])/100000
    This returns a basically random number between 0 and 1 (so you can mulitply it by your maximum value) based on the numeric fraction of a second of the start time of the process.

  • Problem with random number generation

    hey forum, i wonder if anyone can help me out with a small problem with my university coursework (yep its homework!!!)
    heres my problem, i am writing one of them 8 puzzle problems (the one based around sam lloyds 15 puzzler), i can successfully generate one random sequence of numbers with no duplicates, but whenever i call the random method again it keeps producing the same results
    heres the code
    in my main class file
    if(e.getSource() == randomButton) {
          new RandomPuzzle();
          System.out.println(random.randState);
          //startStateString = new RandomPuzzle();
    }heres my number generator class file
    import java.util.Random;
    import java.io.*;
    public class RandomPuzzle
         /** Base Random number generator */
        Random rn = new Random();
        /** Puzzle holder */
        byte b[];
        long number = 0;
        String randState = "";
        /** Default constructor */
        public RandomPuzzle() {
            rn.setSeed(number);
            b = new byte[9];
            randState = randomString();
        /** Provide range for generation */
        public int rand(int lo, int hi) {
            int n = hi - lo + 1;
            int i = rn.nextInt() % n;
            if (i < 0)
            i = -i;
            return lo + i;
        /** Set size for array */
        public int rand( int hi){
            int n = hi;
                return n;
        /** Check for duplicate values within the same configuration */
        boolean valueExists( byte value ) {
            int i = b.length;
            boolean exists = false;
            for( int j = 0; j < i; j++ ){
                if( b[j] == value )
                    exists = true;
            return exists;
        /** returns the actual string */
        public String randomString(int lo, int hi) {
            int n = rand( 9 );
            //boolean valueEntered = false;
            for (int i = 0; i < 9; i++) {
                boolean valueEntered = false;
                byte temp = (byte)rand('0', '8');
                while( valueEntered == false ) {
                    if( !valueExists( temp ) ) {
                         b[i] = temp;
                         valueEntered = true;
                    else
                        temp = (byte)rand('0', '8');
            return new String(b, 0);
        /** calls above function */
        public String randomString() {
            return randomString(0, 8);
    }i've tried for hours to work this out, but i am stumped. if anyone can point me in the right direction, maybe point out the problem code and give one or two tips i would be forever in your debt
    thanx in advance
    korbitz

    thanx for the help paulcw, but when i removed the seed code it done the same
    but i added this to my main class and now it works fine
    if(e.getSource() == randomButton) {
                   RandomPuzzle temp = new RandomPuzzle();
                   System.out.println(temp.randState);
                   //startStateString = new RandomPuzzle();
              }thanx again for your help

  • Need help with a JavaScript to generate random number

    Hi
    First things first. I don't know the J of JavaScript.
    When I was thinking of some readymade solution to generate a random number in Captivate, I found this on a LinkedIn forum.
    1) Add a user variable to your project called "randomNumber". It's value can be zero.
    2) Add a Text Caption with "$$randomNumber$$" in it, to check whether your script is working.
    3) Add a button to the slide. Give it an On Success Action of Execute JavaScript. Turn off it's "Continue Playing the Project" checkbox.
    4) Add the following text in the button's Script_Window:
    var objCP = document.Captivate;
    var rand = 1 + Math.floor(Math.random() * 10);
    function onButtonClick(){
    objCP.cpEISetValue('randomNumber', rand);
    onButtonClick();
    However, this is (as the poster in the forum warned) not working for Captivate 7. Can somebody please help?
    I am open for any other methods of getting the same result.
    Thanks in advance,
    Sreekanth

    Hi Sreekanth,
    When testing, make sure you are testing from a web server where the web address begins with http or https.  When setting the captivate variable "randomNumber" try this instead:
    objCP.cpEISetValue('m_VarHandle.randomNumber', rand);
    That will only work for SWF output.  If you want it to work for both HTML5 and SWF output, try this code:
    window.onButtonClick = function(){
              var rand = generateRandomNumber(1, 10);
              setCpVariable('randomNumber', rand);
    window.generateRandomNumber = function(min, max){
              var randomNum = 0;
              if(!isNaN(parseFloat(min)) && !isNaN(parseFloat(max))){
                        min = Number(min);
                        max = Number(max);
                  randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
              return randomNum;
    window.setCpVariable = function (cpUserVariableName, variableValue) {
              /* Check for HTML5 vs. SWF output */
              if (typeof window.cp === 'undefined') {
                        /* We have SWF output, so Get the Captivate Object */
                        var objCp = document.getElementById('Captivate');
                        if (objCp && objCp.cpEISetValue) {
                                  /* Set the Captivate User variable with the JavaScript variable, variableValue */
                                  objCp.cpEISetValue('m_VarHandle.' + cpUserVariableName, variableValue);
              } else {
                        /* We have HTML5 output */
                        /*If variable does not exist off of the window object, then use the variables manager*/
                        if (typeof window[cpUserVariableName] === 'undefined') {
                                  if (cp.vm && cp.vm.setVariableValue) {
                                            cp.vm.setVariableValue(cpUserVariableName, variableValue);
                        } else {
                                  window[cpUserVariableName] = variableValue;
    window.onButtonClick();
    Be sure to test this from a web server or else local security will prevent the javascript from executing.
    Best,
    Jim Leichliter

  • Random Number generation within BPEL

    I am trying to embed a java-exec and trying to generate random number using a code as follows:
    int ranNumber1 = (int)(Math.random()*1000000000000000.0);
    int ranNumber2 = (int)(Math.random()*1000000000000000.0);
    setVariableData("RanNumber1",new Integer(ranNumber1));
    setVariableData("RanNumber2",new Integer(ranNumber2));
    I always get the same value for ranNumber1 and for ranNumber2 and for every instance, the value seems to be the same.. Actually the value generated is 2147483647 always..
    Am I doing anything wrong? Can anyone clarify here, please...

    // construct a bigdecimal, exaclty lenght'd 10 digits
    BigDecimal z = new BigDecimal("10000000000");
    // multiply it randomly (random returns something between 0 and 1)
    z = z.multiply(new BigDecimal(Math.random()));
    // and use the rounding ..
    BigInteger big = z.toBigInteger();
    is one option, I guess not the nicest but working ..

  • Random number generation with format 18XX88YYYYY

    I have been tryig to generate random numbers having
    format 18xx88yyyyy
    here
    18 followed by two random number then 88 followed by five random number. here 18 and 88 are fixed at location one,two,five and sixth position.
    but I am unable to get the logic .
    So please help
    Thanx
    Achyot

    After changing the column from number to varchar2 I am getting my correct result...
    create or replace function generateRandom return varchar2 is
    random varchar2(11);
    begin
    SELECT '18'|| lpad(ROUND (DBMS_RANDOM.VALUE (0, 100)),2,'0')|| '88'|| lpad(ROUND (DBMS_RANDOM.VALUE (0,
    100000)),5,'0')
    into random FROM DUAL;
    return random;
    end;
    create or replace procedure insertRandom is
    getNum varchar2(11);
    x number(3);
    cnt number;
    cursor checkpk is
    select random_no n from rand_no;
    begin
    cnt:=0;
    while (cnt<3054) loop
    x:=0;
    getNum:=generateRandom;
    for pkcheck in checkpk loop
    if getNum=pkcheck.n then
    x:=x+1;
    end if;
    end loop;
    if x=0 then
    insert into rand_no values(getNum);
    end if;
    select count(*) into cnt from rand_no;
    end loop;
    commit;
    end insertRandom;
    output:
    RANDOM_NO
    18388817929
    18658842315
    18028870847
    18898822037
    18678818255
    18248878003
    18558852407
    18878870907
    18998892135
    18538876212
    18908820740
    Thanx you everyone...

  • Random Number list

    Lo peeps, I have a small problem, i'm trying to create a random number generator and create a list of size current_size. The code also generates the random number from zero to current_size. The following code seems to work correctly in generating a random number, but it doesn't create a list of random numbers, instead it creates a list of the same random number!!! Does anyone have any ideas?
    import java.util.*;       // needed for Random
    public class ListByArray
        private     int           current_size;
        private     String[]      data;
        private final int        default_max_size = 4096;
        public int createRandomList(String string_size)
            int i;
            int j;
            if(!isIntString(string_size)) {
                return 0;
            else {
                Integer size = Integer.valueOf(string_size);
                current_size = size.intValue();
            for(i=0; i<current_size; i++) {
                Random R = new Random();
                j = (int)(R.nextFloat()*current_size);
                data[i] = Integer.toString(j);
            return current_size;
        } //end createRandomList
    } //end classIt's manly the for loop which I'm wondering about because I know the rest of the code works!!!.

    That line creates a new pseudo random number generator with the current time (in milliseconds) as a seed. When you call r.nextFloat you don't actually get a random number but a number that is a function of the last number generated, or, if there are no numbers yet generated, of the seed (that's why they call them pseudo random number generators). So the sequence you get is totally dependent on the seed. Your loop seems to be passed so fast that the time in milliseconds doesn't change during it, with the result that you have many generators with the exact same seed and will produce the exact same sequence of numbers... and you use only the first number of each sequence.
    But if you move the line outside the loop you'll have only one RNG that is seeded only once.
    More info on RNGs: http://directory.google.com/Top/Computers/Algorithms/Pseudorandom_Numbers/

  • Random number in range generator plz help!

    hey hope someone can help me out, im sure its an easy one:
    var tstArray:Array = new Array(1,2,3);
    for (var a:uint=0; a<tstArray.length; a++)
    var x:Number = Math.floor((Math.random()*tstArray[a]));
    trace(x);
    tstArray.splice(a,1);
    i have this code but it doesnt do exectply what i want it to do. Im trying to generate a signle random number per click between 1 and 3 and when all numbers have been used up, remove this click listener.
    if u can help it'll be much appriciated
    thx pavel

    use:
    var fp1:farm_part1=new farm_part1();
    and any time you want to randomize an array use:
    var tstArray:Array = fp1.randomizeF([1,2,3]);
    package
    */import flash.utils.Timer;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.*;
    import flash.media.Sound;
    import flash.events.TimerEvent;
    import flash.media.SoundChannel;
    import flash.media.SoundTransform;*/
    public class farm_Part1
    public function randomizeF(a:Array):Array
    {a.shuffle();
    return a;
    ///////////////////////////// change nothing below /////////////////////////////////////////
    function shuffle(a:Array)
    var p:int;
    var t:*;
    var ivar:int;
    for (ivar = a.length-1; ivar>=0; ivar--)
    p=Math.floor((ivar+1)*Math.random());
    t = a[ivar];
    a[ivar] = a[p];
    a[p] = t;
    }//randomAnimal
    }//class
    }//package

  • Random number

    How to make sure the random number is positive??

    Is it true??public int nextInt(int n)
    Returns a pseudorandom, uniformly distributed
    int value between 0 (inclusive) and the specified
    value (exclusive), drawn from this random number
    generator's sequence. The general contract of nextInt is
    that one int value in the specified range is pseudorandomly
    generated and returned. All n possible int values are
    produced with (approximately) equal probability.>> Is it Math.random() will return a double type number??public static double random()
    Returns a double value with a positive sign,greater than or equal to 0.0 and less than 1.0. Returned
    values are chosen pseudorandomly with (approximately)
    uniform distribution from that range.(both taken from the API docs at http://java.sun.com/j2se/1.4.2/docs/api/index.html)

  • Random number issue

    I'm making a mobile game and I can't seem to generate a random number successfully
    Game.java:
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    public class Game extends MIDlet implements CommandListener {
    private Display theDisplay;
    private GameCanvas canvas;
    private Player p1;
    private Block[] Grid;
    static final Command exitCommand = new Command("Exit", Command.STOP, 1);
    class Player {
      public int x, y;
      public int width=60, height=15;
      public Player(int curX, int curY) {
       x = curX;
       y = curY;
    public Game() {
      setupGrid(5, 8, 5);
      p1 = new Player(90, 250);
      theDisplay = Display.getDisplay(this);
    private void setupGrid(int rows, int cols, int cellspacing) {
      Grid = new Block[200];
      int ind = 0;
      int posX = 10;
      int posY = 20;
      int colPosY;
      int colPosX;
      colPosY = posY;
      colPosX = posX;
      for(int x = 0; x < rows; x++) {
       Grid[ind] = new Block(posX, posY);
       colPosY = posY;
       for(int y = 0; y < cols; y++) {
        ind++;
        colPosX += 20+cellspacing;
        colPosY = posY;
        Grid[ind] = new Block(colPosX, colPosY);
       colPosX = posX;
       posY += 15+cellspacing;
       ind++;
    class Block {
       public int x, y;
       public int Health;
       public int r = 0, g = 0, b = 0;
       public Block(int curX, int curY) {
       x = curX;
       y = curY;
       double rand = Math.random()*5;
       if(rand > 0 && rand < 2) {
        g = 255;
        r = 0;
        b = 0;
       if(rand > 2 && rand < 4) {
        r = 255;
        g = 0;
        b = 0;
       if(rand > 3 && rand < 5) {
        b = 255;
        g = 0;
        r = 0;
    class GameCanvas extends Canvas {
      private int width;
      private int height;
      GameCanvas() {
       width = getWidth();
       height = getHeight();
      public void paint(Graphics g) {
       g.setColor(0, 0, 0);
       g.fillRect(0, 0, width, height);
       g.setColor(100, 100, 100);
       g.fillRect(p1.x, p1.y, p1.width, p1.height);
       for(int x = 0; x < Grid.length; x++) {
        if(Grid[x] != null) {
         g.setColor(Grid[x].r, Grid[x].g, Grid[x].b);
         g.fillRect(Grid[x].x, Grid[x].y, 20, 10);
      public void keyPressed(int keyCode) {
       int key = getGameAction(keyCode);
       if(key == LEFT && p1.x > 0) {
        p1.x-=4;
       else if(key == RIGHT && p1.x < canvas.width-p1.width) {
        p1.x+=4;
       repaint();
    protected void startApp() throws MIDletStateChangeException {
      canvas = new GameCanvas();
      canvas.addCommand(exitCommand);
      canvas.setCommandListener(this);
      theDisplay.setCurrent(canvas);
    public void pauseApp() { }
    public void destroyApp(boolean unconditional) { }
    public void commandAction(Command c, Displayable d) {
      if(c == exitCommand) {
       destroyApp(false);
       notifyDestroyed();
    }Game.java:58: cannot find symbol
    symbol : method random()
    location: class java.lang.Math
    double rand = Math.random()*5;
    ^
    1 error
    Line 58:
    double rand = Math.random()*5;

    b1nary wrote:
    Unfortunately, no - it won't work. Prior to posting this thread I researched different ways to generate random numbers but, apparently, the WTK only allows certain packages to be recognized.You can always write your own generator. For portability I use
    * Uniform random number generator.
    * <p>
    * Based on
    * <blockquote>
    * <pre>
    * Efficient and Portable Combined Random Number Generators
    * <a href="http://www.iro.umontreal.ca/~lecuyer">Pierre L'Ecuyer</a>
    * Communications of the ACM
    * June 1988 Volume 31 Number 6
    * </pre>
    * </blockquote>
    * @author Sabre
    public class Ecuyer
         * Constructs the generator based on two starting seeds.
         * <p>
         * Two generators using the same pair of seeds will produce
         * exactly the same sequence of pseudo random numbers.
         * @param seed1 the starting seed.
         * @param seed2 the second starting seed.
        public Ecuyer(int seed1, int seed2)
            s1 = (seed1 > 0) ? seed1 : 1;
            s2 = (seed2 > 0) ? seed2 : 1;
         * Constructs the generator based on a starting seed.
         * <p>
         * Two generators using the same seeds will produce
         * exactly the same sequence of pseudo random numbers.
         * @param seed the starting seed.
        public Ecuyer(long seed)
            this((int) ((seed >> 32) & 0x7fffffff), (int) (seed & 0x7fffffff));
         * Constructs a generator using the current time as seed.
        public Ecuyer()
            this(System.currentTimeMillis());
         * Returns the next random number
         * @return the next random number
        public double nextValue()
                // m = 2147483563, a = 40014
                int k = s1 / q1;
                s1 = a1 * (s1 - k * q1) - k * r1;
                if (s1 < 0)
                    s1 += m1;
                // m = 2147483399, a = 40692
                int k = s2 / q2;
                s2 = a2 * (s2 - k * q2) - k * r2;
                if (s2 < 0)
                    s2 += m2;
            int z = s1 - s2;
            if (z < 0)
                z += m1;
            return z * 4.656613e-10;
        static final int m1 = 2147483563;
        static final int a1 = 40014;
        static final int q1 = 53668;
        static final int r1 = 12211;
        static final int m2 = 2147483399;
        static final int a2 = 40692;
        static final int q2 = 52774;
        static final int r2 = 3791;
        private int s1;
        private int s2;
    }Make sure you test it thoroughly before committing to it.

Maybe you are looking for