Multiple Random Number Generators

I'm writing a program to simulate the tossing of two coins: a nickel and a dime. I want each coin to have its own independently generated set of outcomes. At the core of my logic is a call to one of two random number generators.
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Math.html#random() says that "...it may reduce contention for each thread to have its own pseudorandom-number generator." It also makes reference to Random.nextDouble.
If the first call to random() creates the random number generator, and any subsequent calls to random() supply the next number in the series, what code do I use to setup multiple generators? I want each coin to have its own series.
What is the need for nextDouble()? Should I be using nextDouble() or random() to get subsequent numbers from these generators?
Thanks for you help.
Jim

Random rnd1 = new Random(7);
Random rnd2 = new Random(17);Unfortunately, the close seed states will make for
very closely related sequences from each.And you base that statement on what?Close seeds make for close sequences with lcprng's.
It's less obvious for these:
// First ten calls to nextInt()
-1156638823
-1149713343
-1552468968
-876354855
-1077308326
-1299783908
41356089
-1761252264
1495978761
356293784
2107132509
1723477387
-441191359
-789258487
-1105573998
-46827465
-1253369595
190636124
-1850488227
-672335679But that's because the generator is 48 bits.
If you look at sequential seeds you get really bad results...
// first 50 seeds, [0, 50), one call to nextInt
0  -1155484576
1  -1155869325
2  -1154715079
3  -1155099828
4  -1157023572
5  -1157408321
6  -1156254074
7  -1156638823
8  -1158562568
9  -1158947317
10 -1157793070
11 -1158177819
12 -1160101563
13 -1160486312
14 -1159332065
15 -1159716814
16 -1149328594
17 -1149713343
18 -1148559096
19 -1148943845
20 -1150867590
21 -1151252339
22 -1150098092
23 -1150482841
24 -1152406585
25 -1152791334
26 -1151637087
27 -1152021836
28 -1153945581
29 -1154330330
30 -1153176083
31 -1153560832
32 -1167796541
33 -1168181290
34 -1167027043
35 -1167411792
36 -1169335537
37 -1169720286
38 -1168566039
39 -1168950788
40 -1170874532
41 -1171259281
42 -1170105035
43 -1170489784
44 -1172413528
45 -1172798277
46 -1171644030
47 -1172028779
48 -1161640559
49 -1162025308

Similar Messages

  • Do random number generators (RNGs) depend on sequential number generation?

    Hi,
    I know that random number generators (RNGs) are guaranteed to be random as N (the number of numbers generated) approaches infinity, but what does the specification say about throwing away the RNG after a single use?
    That is, is there a difference between generating 1000 numbers using the same generator versus generating 1000 generators and reading at one number from each?
    Is there a difference between the normal RNGs and the cryptographically-strong ones for this?
    I ask because I am wondering whether a web server needs to maintain a RNG per client session, or whether it can share a single generator across all clients, or whether it can create a new generator per HTTP request. Does any of this affect how random the resulting numbers will be (from the client point of view, as T approaches infinity)?
    Thank you,
    Gili

    ghstark wrote:
    cowwoc wrote:
    I know that random number generators (RNGs) are guaranteed to be random as N (the number of numbers generated) approaches infinityHow do you know this? it is a challenge just to come up with a formal definition for the "random" in "random number generators".
    Wasn't this covered in your [earlier thread|http://forums.sun.com/thread.jspa?threadID=5320382&messageID=10369834] ?
    You're right, but what bothered me about that thread is that the replies concluded that since there is no practical proof that SecureRandom has a problem that should be good enough. I'm looking for a code sniplet guaranteed by the specification (hence portable across implementations) to generate random numbers. No one has yet to provide such an answer.
    What's to guarantee that if I move to a different platform, vendor or even a different version of Sun's JVM that my code won't magically break? Verifying randomness isn't a trivial matter.

  • Ideas on generating seeds for random number generators?

    Does anyone here have any ideas or know of any good links to articles that discuss how to generate good seeds for random number generators?
    I am aware that I could always probably call SecureRandom.generateSeed as one technique.
    The major problem that I have with the above is that I have no idea how any given implementation of SecureRandom works, and whether or not it is any good. (For instance, Sun seems to hide their implementation outside of the normal JDK source tree; must be in one of their semi-proprietary sun packages...)
    I thought about the problem a little, and I -think- that the implementation below ought to be OK. The javadocs describe the requirements that I am looking for as well as the implementation. The only issue that still bugs me is that maybe the hash function that I use is not 1-1, and so may not guarantee uniqueness, so I would especially like feedback on that.
    Here's the code fragments:
         * A seed value generating function for Random should satisfy these goals:
         * <ol>
         *  <li>be unique per each call of this method</li>
         *  <li>be different each time the JVM is run</li>
         *  <li>be uniformly spread around the range of all possible long values</li>
         * </ol>
         * This method <i>attempts</i> to satisfy all of these goals:
         * <ol>
         *  <li>
         *          an internal serial id field is incremented upon each call, so each call is guaranteed a different value;
         *          this field determines the high order bits of the result
         *  </li>
         *  <li>
         *          each call uses the result of {@link System#nanoTime System.nanoTime}
         *          to determine the low order bits of the result,
         *          which should be different each time the JVM is run (assuming that the system time is different)
         *  </li>
         *  <li>a hash algorithm is applied to the above numbers before putting them into the high and low order parts of the result</li>
         * </ol>
         * <b>Warning:</b> the uniqueness goals cannot be guaranteed because the hash algorithm, while it is of high quality,
         * is not guaranteed to be a 1-1 function (i.e. 2 different input ints might get mapped to the same output int).
         public static long makeSeed() {
              long bitsHigh = ((long) HashUtil.enhance( ++serialNumber )) << 32;
              long bitsLow = HashUtil.hash( System.nanoTime() );
              return bitsHigh | bitsLow;
         }and, in a class called HashUtil:     
         * Does various bit level manipulations of h which should thoroughly scramble its bits,
         * which enhances its hash effectiveness, before returning it.
         * This method is needed if h is initially a poor quality hash.
         * A prime example: {@link Integer#hashCode Integer.hashCode} simply returns the int value,
         * which is an extremely bad hash.     
         public static final int enhance(int h) {
    // +++ the code below was taken from java.util.HashMap.hash
    // is this a published known algorithm?  is there a better one?  research...
              h += ~(h << 9);
              h ^=  (h >>> 14);
              h +=  (h << 4);
              h ^=  (h >>> 10);
              return h;
         /** Returns a high quality hash for the long arg l. */
         public static final int hash(long l) {
              return enhance(
                   (int) (l ^ (l >>> 32))     // the algorithm on this line is the same as that used in Long.hashCode
         }

    Correct me if I'm incorrect, but doesn't SecureRandom just access hardware sources entropy? Sources like /dev/random?What do you mean by hardware sources of entropy?
    What you really want is some physical source of noise, like voltage fluctuations across a diode, or Johnson noise, or certain radioactive decay processes; see, for example
         http://www.robertnz.net/true_rng.html
         http://ietfreport.isoc.org/idref/draft-eastlake-randomness2/
         this 2nd paper is terrific; see for example this section: http://ietfreport.isoc.org/idref/draft-eastlake-randomness2/#page-9
    But is /dev/random equivalent to the above? Of course, this totally depends on how it is implemented; the 2nd paper cited above gives some more discussion:
         http://ietfreport.isoc.org/idref/draft-eastlake-randomness2/#page-34
    I am not sure if using inputs like keyboard, mouse, and disk events is quite as secure as, say, using Johnson noise; if my skimming of that paper is correct, he concludes that you need as many different partially random sources as possible, and even then "A hardware based random source is still preferable" (p. 13). But he appears to say that you can still do pretty good with these these sources if you take care and do things like deskew them. For instance, the common linix implementation of /dev/random at least takes those events and does some sophisticated math and hashing to try to further scramble the bits, which is what I am trying to simulate with my hashing in my makeSeed method.
    I don't think Java can actually do any better than the time without using JNI. But I always like to be enlightened; is there a way for the JVM to generate some quality entropy?Well, the JVM probably cannot beat some "true" hardware device like diode noise, but maybe it can be as good as /dev/random: if /dev/random is relying on partially random events like keyboard, mouse, and disk events, maybe there are similar events inside the JVM that it could tap into.
    Obviously, if you have a gui, you can with java tap into the same mouse and keyboard events as /dev/random does.
    Garbage collection events would probably NOT be the best candidate, since they should be somewhat deterministic. (However, note that that paper cited above gives you techniques for taking even very low entropy sources and getting good randomness out of them; you just have to be very careful and know what you are doing.)
    Maybe one source of partial randomness is the thread scheduler. Imagine that have one or more threads sleep, and when they wake up put that precise time of wakeup as an input into an entropy pool similar to the /dev/random pool. Each thread would then be put back to sleep after waking up, where its sleep time would also be a random number drawn from the pool. Here, you are hoping that the precise time of thread wakeup is equivalent in its randomness to keyboard, mouse, and disk events.
    I wish that I had time to pursue this...

  • Support for hardware random number generators?

    Can a hardware random number generator be easy integrated into Solaris so that it is accessed via /dev/urandom or /dev/random?
    Hardware Random Number Generators such as (just googling "usb hardware random number generator")
    http://true-random.com/
    http://www.protego.se/
    http://www.araneus.fi/products-alea-eng.html
    http://www.westphal-electronic.de/zranusbe.htm
    Is it possible to have a generic framework which can work with all these devices?

    This is a forum specifically for Java, not Sun products in general. You might try one on the Solaris forums.

  • Plz help me with random number generators

    cane someone help me write a program that generates 2 random numbers, generates a random operation(+,-,/,*) then ask you for answer, and checks to see if the answer is right, and if not it corrects it for you.
    thank you

    when i do the cases i did the addtion as the first case, and now all i get is addition
    import javax.swing.*;
    import java.text.*;
    import java.util.*;
    public class randomnumbers
         public static void main(String[] arg)
              String input;
              int answer;
              int choice=1;
              Random rand = new Random();
              int num1 = (int) (Math.random()*9+1);
              int num2 = (int) (Math.random()*9+1);
              switch(choice)
                   case 1:System.out.println("What is "+num1+"+"+num2);break;
                   case 2:System.out.println("What is "+num1*'*'*num2);break;
                   default:System.out.println("Illegel Operation");break;          
              input=JOptionPane.showInputDialog("What is the answer?");
              answer=Integer.parseInt(input);
    }

  • What algorithm does Excel 2010 use for Pseudo Random Number Generation (MT19937?)

    Does Excel 2010+ use the Mersenne Twister (MT19937) algorithm for Pseudo Random Number Generation (PRNG), implemented by the RAND() function?
    This has been a nagging question for some time now, with "hints" that it indeed does.  However, a relatively thorough search turns up no definitive documentation.  The most direct indication is perhaps given by Guy Melard [Ref 9] where
    he tests Excel 2010's RAND() function using the Crush battery of tests in TestU01 by L'Ecuyer & Simard.  Melard references a "semi-official" indication that Microsoft did indeed implement MT19937 for the RAND() function in
    Excel 2010, but this reference no longer seems to be available. http://office.microsoft.com/enus/excel-help/about-solver-HP005198368.aspx?pid=CH010004571033.
    The other references below [Ref 1-10] document the history of the statistical suitability of the PRNG and probability distributions in various versions of Excel.  This includes the Wichmann-Hill PRNG implementations supposedly (arguably) used in
    Excel 2003 & 2007 for random number generation.  But still, we have no answer as to which PRNG algorithm is used in
    Excel 2010 (and 2013 for that matter).
    Microsoft indicates that RAND() has been improved in Excel 2010; Microsoft states, "...and the RAND function now uses a new random number algorithm." (see https://support.office.com/en-ca/article/Whats-New-Changes-made-to-Excel-functions-355d08c8-8358-4ecb-b6eb-e2e443e98aac). 
    But no details are given on the actual algorithm.  This is critical for Monte Carlo methods and many other applications.
    Any help would be much appreciated. Thanks.
    [Ref 1] B. McCullough, B. Wilson.  On the Accuracy of Statistical Procedures in Microsoft Excel 97. 
    Computational Statistics & Data Analysis. Vol. 31 No. 1, pp 27-37. July 1999.
    http://users.df.uba.ar/cobelli/LaboratoriosBasicos/excel97.pdf
    [Ref 2]L. Knüsel.  On the accuracy of the statistical distributions in Microsoft Excel 97. Computational Statistics & Data Analysis. Vol. 26 No. 3, pp 375-377. January 1998.
    http://www.sciencedirect.com/science/article/pii/S0167947397817562
    [Ref 3]B. McCullough, B. Wilson.  On the Accuracy of Statistical Procedures in Microsoft Excel 2000 and Excel XP. 
    Computational Statistics & Data Analysis. Vol.40 No. 4, pp 713-721. October 2002.
    https://www.researchgate.net/publication/222672996_On_the_accuracy_of_statistical_procedures_in_Microsoft_Excel_2000_and_Excel_XP/links/00b4951c314aac4702000000.pdf
    [Ref 4] B. McCullough, B. Wilson.  On the Accuracy of Statistical Procedures in Microsoft Excel 2003. 
    Computational Statistics & Data Analysis. Vol.49. No. 4, pp 1244-1252. June 2005.
    http://www.pucrs.br/famat/viali/tic_literatura/artigos/planilhas/msexcel.pdf
    [Ref 5] L. Knüsel. On the accuracy of statistical distributions in Microsoft Excel 2003. Computational Statistics & Data Analysis, Vol. 48, No. 3, pp 445-449. March 2005.
    http://www.sciencedirect.com/science/article/pii/S0167947304000337
    [Ref 6]B. McCullough, D.Heiser.  On the Accuracy of Statistical Procedures in Microsoft Excel 2007. 
    Computational Statistics & Data Analysis. Vol.52. No. 10, pp 4570-4578. June 2008.
    http://users.df.uba.ar/mricci/F1ByG2013/excel2007.pdf
    [Ref 7] A. Yalta. The Accuracy of Statistical Distributions in Microsoft<sup>®</sup> Excel 2007. Computational Statistics & Data Anlaysis. Vol. 52 No. 10, pp 4579 – 4586. June 2008.
    http://www.sciencedirect.com/science/article/pii/S0167947308001618
    [Ref 8] B. McCullough.  Microsoft Excel’s ‘Not The Wichmann-Hill’ Random Number Generators. Computational Statistics and Data Analysis. Vol.52. No. 10, pp 4587-4593. June 2008.
    http://www.sciencedirect.com/science/article/pii/S016794730800162X
    [Ref 9] G. Melard.  On the Accuracy of Statistical Procedures in Microsoft Excel 2010. Computational Statistics. Vol.29 No. 5, pp 1095-1128. October 2014.
    http://homepages.ulb.ac.be/~gmelard/rech/gmelard_csda23.pdf
    [Ref 10] L. Knüsel.  On the Accuracy of Statistical Distributions in Microsoft Excel 2010. Department of Statistics - University of Munich, Germany.
    http://www.csdassn.org/software_reports/excel2011.pdf

    I found the same KB article:
    https://support.microsoft.com/en-us/kb/828795
    This was introduced (according to the article) in Excel 2003. Perhaps the references in notes 2 and 3 might help.
    The article describes combining the results of 3 generators, each similar to a Multiply With Carry (MWC) generator, but with zero carry. MWC generators do very well on the Diehard battery of randomness tests (mentioned in your references), and have
    very long periods. But using zero carry makes no sense to me.
    Combining the three generators only helps if the periods of the 3 are relatively prime (despite what the article implies). Then the period of the result will be the product of the 3 periods. But without knowing the theory behind these generators, I have
    no idea what the periods would be. The formulas for MWC generators fail here.
    Richard Mueller - MVP Directory Services

  • Plot xy graph using random number generator

    How do i plot xy graph dynamically every 5 seconds with a random number generator?
    X axis : Time
    Y Axis : Random number generator

    I've done tis so far. im able to plot dynamically every 1 second.
    but the problem i am facing is The X axis display every 1 second.
    i want it to be fixed 24 hours time format, and the data will gradually plots the data on y axis against x axis every one second, without changing the scale of the x axis (24hour time format)

  • 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 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.

  • RE: Random number keys

    I have a need to generate random number keys for a DB2/6000 database. I am
    expecting 10000 new entries per day to the table and due to design
    constraints need to use an eight digit key. Also for design reasons the key
    on the database is an integer attribute. I have looked at the built in
    random number generator and it only produces a 2 byte number - I need 4.
    Does anyone have a handy routine to produce larger random numbers?
    TIA
    /\/\ark /\/ichols
    "Focus on the QUESTION, not on the ANSWER."
    Lee Wei of Forte contributed a demo called RandomSort to Vol 1. of
    the FShare CDROM. This has some generation code based on the Sedgewick LC
    algorithm that you could probably adapt to your purposes. (e.g. I generated
    8-digit integer values by multiplying Lee Wei's default for MAX by 10).
    You can fiddle with the thing to change the minimum end of the range.
    Robert Sedgewick's Algorithms in C (Addison Wesley 1990) is useful to
    have for this sort of amusement.
    If you don't have access to the FShare 1 CDROM I could send you the
    pex file.
    Regards,
    Stephen Porterfield
    Longs

    There is an excellent book written by Knuth about
    Randon Numbers generator algorithms...
    "The Art of Computer Programming, Donald E. Knuth" -- Vol 2, pp 1-170
    Have a look at these other books if you want more info:
    "Monte Carlo Simulations: Hidden Errors from 'Good' Random Number
    Generators",Physical Review Letters, Alan M.
    Ferrenberg, D. P. Landau, and Y. Joanna Wong, Vol 69 No. 23, Dec 7 1992
    "Monkey Tests for Random Number Generators",Computers Mathematics
    Applications, G Marsaglia, and A Zaman, Vol 26, No
    9 1993, pp 1-10.
    A Current View of Random Number Generators", Computer Science and
    Statistics: 16th Sympossium on Interface, Elsevier,
    1985.
    Hope this helps,
    --francois
    From: Vasas, Marty
    Sent: Thursday, April 10, 1997 8:31 AM
    To: mark h. nichols; forte users
    Subject: RE: Random number keys
    16
    Let's write 2 as twoToThe16th
    If there's nothing built-in to do the job, write a method for the
    following algorithm:
    generate 2 two-byte integers, A and B, from the built-in random number
    generator.
    return A * twoToThe16th + B
    From: mark h. nichols
    Sent: Thursday, April 10, 1997 10:10 AM
    To: forte users
    Cc: vasasm; murthis
    Subject: Random number keys
    MCI Mail date/time: Thu Apr 10, 1997 7:25 am EST
    Source date/time: Thu, 10 Apr 1997 06:37:17 -0500
    I have a need to generate random number keys for a DB2/6000 database. I
    am
    expecting 10000 new entries per day to the table and due to design
    constraints need to use an eight digit key. Also for design reasons the
    key
    on the database is an integer attribute. I have looked at the built in
    random number generator and it only produces a 2 byte number - I need 4.
    Does anyone have a handy routine to produce larger random numbers?
    TIA
    /\/\ark /\/ichols
    "Focus on the QUESTION, not on the ANSWER."

  • Random number keys

    I have a need to generate random number keys for a DB2/6000 database. I am
    expecting 10000 new entries per day to the table and due to design
    constraints need to use an eight digit key. Also for design reasons the key
    on the database is an integer attribute. I have looked at the built in
    random number generator and it only produces a 2 byte number - I need 4.
    Does anyone have a handy routine to produce larger random numbers?
    TIA
    /\/\ark /\/ichols
    "Focus on the QUESTION, not on the ANSWER."

    There is an excellent book written by Knuth about
    Randon Numbers generator algorithms...
    "The Art of Computer Programming, Donald E. Knuth" -- Vol 2, pp 1-170
    Have a look at these other books if you want more info:
    "Monte Carlo Simulations: Hidden Errors from 'Good' Random Number
    Generators",Physical Review Letters, Alan M.
    Ferrenberg, D. P. Landau, and Y. Joanna Wong, Vol 69 No. 23, Dec 7 1992
    "Monkey Tests for Random Number Generators",Computers Mathematics
    Applications, G Marsaglia, and A Zaman, Vol 26, No
    9 1993, pp 1-10.
    A Current View of Random Number Generators", Computer Science and
    Statistics: 16th Sympossium on Interface, Elsevier,
    1985.
    Hope this helps,
    --francois
    From: Vasas, Marty
    Sent: Thursday, April 10, 1997 8:31 AM
    To: mark h. nichols; forte users
    Subject: RE: Random number keys
    16
    Let's write 2 as twoToThe16th
    If there's nothing built-in to do the job, write a method for the
    following algorithm:
    generate 2 two-byte integers, A and B, from the built-in random number
    generator.
    return A * twoToThe16th + B
    From: mark h. nichols
    Sent: Thursday, April 10, 1997 10:10 AM
    To: forte users
    Cc: vasasm; murthis
    Subject: Random number keys
    MCI Mail date/time: Thu Apr 10, 1997 7:25 am EST
    Source date/time: Thu, 10 Apr 1997 06:37:17 -0500
    I have a need to generate random number keys for a DB2/6000 database. I
    am
    expecting 10000 new entries per day to the table and due to design
    constraints need to use an eight digit key. Also for design reasons the
    key
    on the database is an integer attribute. I have looked at the built in
    random number generator and it only produces a 2 byte number - I need 4.
    Does anyone have a handy routine to produce larger random numbers?
    TIA
    /\/\ark /\/ichols
    "Focus on the QUESTION, not on the ANSWER."

  • Generating random number

    Hi
    I am making an assignment in which I have a discrete random number tellig the probaily of the locations of a person in a city.There are around 50 locations and probablity for each is calculated.Now in my program I have to randomly choose 1 location.Can anyone tell me how to do it.I know there is Random Class in java.util package but thats for continuous random numbers and also I dont have much knowledge about random number generators.
    thanks in advance

    P.S. The doube data type isavailable only in JDK versions 9.72 and above.
    Ok very funny, we all know he meant "doobie"Well, I, for one, thought he meant "doubt"...asin, "I have a doubt in ...". ;)
    Oh No! They got you too? :(Quick! Burn her before it spreads even further!No, no! I didn't even think about it until after the
    "doobie" was posted as the correct word instead of
    "doube". But, given where some people here think
    this use of "doubt" originates [countrywise], maybe
    other influences caused me to think of it...
    I would never say "doubt" in that context
    myself.We have to use science to make sure we are doing the right thing! Does anyone have a duck and a big wooden scale?
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Favorite random number generator.

    As I hope that not everyone is using the core java API for generating random ints, floats, etc., I was curious what RNG (random number generators) people are using. I am currently using the Mersenne Twister Fast, and have glanced at the RNG in the Colt API. What do you use? What is your favourite RNG?

    I also favor this crisp random number generator, which is adapted to Java from the book "Numerical Recipes in C++".
    http://www.nr.com/cpp-blurb.html
    public class Ran {
                  private int idum;
                 final static int IA = 16807;
         final static int IM = 2147483647;
         final static int IQ = 127773;
         final static int IR = 2836;
         final static int MASK = 123459876;
         final static double AM = 1.0 / (double)IM;
                Ran(){
                    this.idum = (int)(System.currentTimeMillis()%262144L);
                Ran(int n){
                    this.idum = n;
        final public double rand(){
         this.idum ^= MASK;
         int k = this.idum / IQ;
         this.idum = IA*(this.idum - k*IQ) - IR*k;
         if(this.idum < 0){this.idum += IM;}
         double ans = AM*this.idum;
         this.idum ^= MASK;
         return ans;
    }(This is a privately converted version, not published.)

  • VBScript Truly Random Number/Password Generators?

    So... I have a script that generates random passwords for use in a project in VBS.  The code used to generate the password is something that is very similar to this blog post: 
    http://blogs.msdn.com/b/gstemp/archive/2004/02/23/78434.aspx.  And considering every random-number generator in VBS that I was able to find appears to be based (at least, in part)
    off of this code, I'm looking for something that is reliable. 
    The above blog article basically states that the builtin Rnd and Randomize functions are not functionally secure for password generation because of the small number of "seeds" that vbscript has builtin to it's randomize/rnd functions.  And because of
    this small number of seeds, it's relatively easy to deduce the password because of it.  So ultimately, I'm asking to know if there is a reliable way to generate, "truly random" numbers that are secure enough for password values (through random number
    -> ANSI character translation)?
    The article talks about the Crypto API being able to generate truly random numbers but I wasn't able to find any documentation on how to access the Crypto API from VBS.  Can anyone provide any assistance on either of these two questions?  Thanks.

    @Richard
    The Rnd() function does not appear to be good enough for me.  I'm testing password generation on different machines at startup and writing those values to AD.  What I've seen is a preponderance of either "very close" or identical passwords from
    using this general code:
    Randomize
    rndNum = Int((122 - 33 + 1) * Rnd + 33)
    ...who's value gets converted to a character and appended to a string that gets repeated x times to generate a password.  To show you what spawned this entire thread, my computers (that are all running this at startup), are generating passwords that
    look like this:
    "ua*td"4poYAp=SlL
    #ua+td"4ppZBq>SlL
    #vb+ue#5qpZBr>TmM
    $wc-vf$6rq[Ds?UnN
    $wc-vf$6rq[Ds?UnN
    $wc-vf$6rr[Ds@UnN
    -%k5$n,>zzdL!H^vV
    %wd-vf%6sr\Ds@VoN
    &ye.xh&8ts]EtAWpP
    &ye/xh&8tt]FuBWpP
    (!g0zj(:vu_GwCYrR
    (!g0zj(:vu_HwCYrR
    )!g1zj(:vv`HwDZrR
    )!h1!k):wv`HwDZsS
    *"h2!k);wwaIxEZsS
    *"i2!k*;xwaIxE[tS
    *#i2"l*<xwaIyE[tT
    *#i3"l*<xxbJyF[tT
    *6"F5%=O11u]2Yo-g
    ,$j4#m+=yycKzG]uU
    ,%k5$n,>zycL!H]vV
    .'m6&p.@"!eM"I_xX
    /'n7&p/@#"fN#J`yX
    :2xB1!9K--qY.Uk)c
    :2xB1!9K--qY.Uk)c
    :2xB1!9K--qY.Uk)c
    :2yB1!9K.-qY.Uk)c
    :2yB1!9K.-qY.Uk)c
    :2yB2":K.-qY.Uk*d
    :3yC2":L..qZ/Vk*d
    :3yC2":L..qZ/Vk*d
    ;3yC2":L..rZ/Vl*d
    ;4zC3#;M/.rZ0Vl+e
    ;4zC3#;M/.rZ0Vl+e
    ;4zD3#;M/.r[0Vl+e
    ?7#G6&>P22v^3Zo.h
    ?7#G6&>P22v^3Zo.h
    ?7#G6&>P22v^3Zp.h
    ?7#G6&>P32v^3Zp.h
    ?7$G6&>P32v^3Zp.h
    ?7$G7'?P32v^3Zp/i
    ?8$G7'?Q32v^3Zp/i
    ?8$Gn^v.jjS<k8MfF
    ?8$H7'?Q32v_4Zp/i
    @8$H7'?Q33w_4[q/i
    @9%I8(@R43w`5[q0j
    @9%I8(@R44w`5\q0j
    [S?cRBZlNN8zOv2J*
    [S@cRB[lON8zOv2K*
    [S@cRBZlON8zOv2J*
    [T@cSC[mON8zPv2K+
    [T@cSC[mON8zPv2K+
    [T@dSC[mOO9!Pw2K+
    \kW!jZr*ffP8g4IbB
    \T@dSC[mOO9!Pw2K+
    \T@dSC[mOO9!Pw3K+
    \T@dSC[mOO9!Pw3K+
    \T@dSC[mOO9!Pw3K+
    \TAdSC[mPO9!Pw3L+
    \UAdTD\nPO9!Qw3L,
    \UAeTD\nPP:"Qx3L,
    ]UAeTD\nPP:"Qx4L,
    ]VBeUE]oQP:"Qx4M-
    ]VBfUE]oQP:#Rx4M-
    ^VBfUE]oQQ;#Ry4M-
    ^VCfUE]oRQ;#Ry5M-
    ^WCfVF^pRQ;#Ry5N.
    ^WCfVF^pRQ;#Ry5N.
    _WCgVF^pRR<$Sz5N.
    _WCgVF^pRR<$Sz5N.
    _WCgVF^pRR<$Sz6N.
    _WCgVF^pRR<$Sz6N.
    _XDhWG_qSS<%T!6O/
    `XEhWG_qTS=%T!7O/
    `YEhXH`rTS=%T!7P0
    `YEhXH`rTS=%U!7P0
    `YEhXH`rTS=%U!7P0
    `YEhXH`rTS=%U!7P0
    `YEhXH`rTS=&U!7P0
    `YEiXH`rTS=&U!7P0
    `YEiXH`rTS=&U!7P0
    `YEiXH`rTT=&U"7P0
    +#i3"l*<xxbJyF[tT
    +#i3"l*<xxbJyF[tT
    +$j3#m+=yxbJyF\uU
    +$j4#m+=yxbKzF\uU
    <4!D4$<M0/s[0Wm,f
    <4zD3#;M//s[0Wl+e
    <5!D4$<N0/s[0Wm,f
    <5!E4$<N0/s\1Wm,f
    =5!E4$<N00t\1Xm,f
    =5"E4$=N10t\1Xn-f
    =6"E5%=O10t\2Xn-g
    =6"E5%=O10t]2Xn-g
    =6"F5%=O11t]2Yn-g
    =6"F5%=O11t]2Yn-g
    >6"F5%=O11u]2Yn-g
    >6#F5%=O21u]2Yo-g
    >6#F5&>O21u]2Yo.g
    >7#F6&>P21u]2Yo.h
    >7#G6&>P21u^3Yo.h
    0(n8'q/A##gO$KayY
    0(n8'q/A##gO$KayY
    0(o8(r0A$#gO$KazZ
    0(o8'q/A$#gO$KayY
    0)o9(r0B$#gP%KazZ
    0)o9(r0B$#gP%KazZ
    0)o9(r0B$$gP%LazZ
    1)o9(r0B$$hP%LbzZ
    1)o9(r0B$$hP%LbzZ
    1*p:)s1C%$hQ&Lb![
    1*p:)s1C%%hQ&Mb![
    1*p9)s1C%$hQ&Lb![
    2*p:)s1C%%iQ&Mb![
    2+q:*t2D&%iQ&Mc"\
    2+q:*t2D&%iQ'Mc"\
    4,s<,v4E('kS(Oe$^
    4'm7&p.@"!eN#I_xX
    4-s<,v4F('kT)Oe$^
    5.t=-w5G)(lT)Pf%_
    5.t=-w5G)(lT*Pf%_
    5.t=-w5G)(lU*Pf%_
    5.t>-w5G))lU*Qf%_
    5.t>-w5G))lU*Qf%_
    5-s=,v4F((lT)Pe$^
    6.t>-w5G))mU*Qf%_
    6.t>-w5G))mU*Qg%_
    6/u?.x6H*)mV+Qg&`
    6/u?.x6H**mV+Rg&`
    6/u?.x6H**nV+Rg&`
    7/u?.x6H**nV+Rh&`
    70v?/y7I+*nV,Rh'a
    70v@/y7I+*nW,Rh'a
    70v@/y7I++nW,Sh'a
    81wA0z8J,,oX-Ti(b
    81wA0z8J,+oX-Si(b
    81wA0z8J,+oX-Si(b
    81wA0z8J,+oX-Si(b
    91wA0z8J,,pX-Tj(b
    91xA0z8J-,pX-Tj)b
    92xA1!9K-,pX.Tj)c
    92xA1!9K-,pX-Tj)c
    92xA1!9K-,pX-Tj)c
    92xB1!9K-,pY.Tj)c
    A:&I9)AS54x`5\r1k
    A:&I9)AS54x`6\r1k
    A9%I8(@R44x`5\q0j
    A9&I9)AR54x`5\r1j
    aYEiXH`rTT>&U"7P0
    aYEiXH`rTT>&U"7P0
    aYEiXH`rTT>&U"8P0
    aYEiXH`rTT>&U"8P0
    aYEiXH`rTT>&U"8P0
    aZFiYIasUT>&U"8Q1
    What you see above is a snippet of the passwords that each computer generates and writes to AD and then sorted through PowerShell to show the similarities/identicals.  I'm only running this on 300ish systems and they seem to be relatively close. 
    As you stated, I'm not sure if the number generators you provided (which were awesome btw) are necessary but unless I'm implementing the Randomize/Rnd functions completely wrong, these passwords seem to be WAY to close for comfort.  I think I'm going
    to try a variation of the GUID usage and run it for awhile to see how "frequent" passwords appear similarly:
    Low = 33
    High = 122
    For i=0 to 100
    WScript.Echo "END: " & GetRandomInt(Low,High)
    Next
    Function GetRandomInt(iLowPart,iHighpart)
    iLowPartLen = Len(iLowPart)
    iHighPartLen = Len(iHighPart)
    ' Loop through dynamically generated GUIDs until we find a string of characters that meet the criteria
    Do
    ' Generate a starting point to read out of a 32-bit GUID string
    Randomize
    iGuidLow = Int(((32 - 8) - 1 + 1) * Rnd + 1)
    ' Generate a GUID
    objGuid = CreateObject("Scriptlet.TypeLib").Guid
    ' Strip out the dashes and braces and pull an 8-character section of the GUID from the provided starting point
    strGuid = Mid(Replace(Replace(Replace(CStr(objGuid), "-", ""), "{", ""), "}", ""), iGuidLow, 8)
    ' Convert back to a number
    iGuid = Abs(CLng("&h" & strGuid))
    iGuidLen = Len(iGuid)
    ' Generate the span of characters to generate given the high/low vals
    Randomize
    iLengthVal = Int((iHighPartLen - iLowPartLen + 1) * Rnd + iLowPartLen)
    ' Loop through the GUID-fragment-converted-to-number to find a value between the given numeric span
    For iStartPos=1 to iGuidLen
    iSegment = CInt(Mid(iGuid, iStartPos, iLengthVal))
    If iSegment >= iLowPart And iSegment <= iHighPart Then
    Exit Do
    Else
    If iSegment > iHighPart Then
    Exit For
    End If
    End If
    Next
    Loop Until iStartPos > iGuidLen
    GetRandomInt = iSegment
    End Function

  • FPGA Poission Random Number

    Hello,
    I have Xilinix Virtex 5 FPGA and i want to implement poisson random number generator.
    FPGA works at 100 MHz clock and at every cycle it should calculate poisson random number. Mean value of poisson distribution can change at every clock cycle. I want to make random time pulse generator with possion distribution. Pulse rate can vary between 1 and 1 billion pulses per second.
    How i can make this generator? Please, help

    b,
    There are two kinds of randomn number generators that are commonly implemented in a FPGA device:  a true random number generator (very hard to do), and a pseudo random number generator (trival to do).
    The pseudo  random generator is done using linear feedback shift registers, and its statistics are well understood, and do not vary (in fact, the sequence repeats depending on the length of the LFSR).
    Attached is a form of true random number generator.
    To get a specific distribution (e.g. Poisson) you would need to verify and [perhaps filter the genberated numbers.
    Poisson being as close to radomn as possible (for example, radioactive decay times are Poisson distributed), a true randomn number generator is where I would start (the attachment).
     

Maybe you are looking for

  • Apple ID to App purchase, how many?

    Ok...So currently with our elementary school we have 50 iPads in use. Since it is an elementary level the students DO NOT have their own Apple ID's for use with the iPads and we have all 50 iPads hooked into the same account regarding the app store a

  • Outboun ucce 7.5

    can anyone tell me me if that field or account number is possible to shown in Layout of ctios toolkit agent for campaign outbound? exist any reports of outbound with AHT statistics? what reports exist for to says a supervisors of reason for customer

  • MM-PUR-OPT-LB Load building without Retail solution

    Hi, has anyone tried to set up automatic load building (module MM-PUR-OPT-LB) in Release ECC 6.0 without using the retail solution? The optimization routines are available but do not work in a non-retail environment. It seems that some retail-related

  • HT5517 I have macbook air and airplay icon is sometimes displayed and sometimes its gone and i am not able to connect to the apple tv. why

    I have apple TV. When I on the bluetooth I am not able to pair my macbook air with my apple tv

  • Sun Java 1.4.2 and MS JVM

    A customer has MSJVM loaded on their win2000 server running SP4. In order to run our application, sun java 1.4.2_07 needs to be loaded. After loading 1.4.2_07, whatever java applet I am trying to load hangs. The screen locks up, and the status bar se