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.

Similar Messages

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

  • 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

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

  • 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

  • Hard code a seed for a random number generator?

    Hi, I need to randomly get either 1 or 0, but in the program I'm running I want to get the same distribution of 1's and 0's every time I run it. I know I need to hardcode the seed in so I use the same seed every time, but I'm not sure how to do this. I know how to use Math.random, and just do
    double randomDouble = Math.random();
    int rand = (int)(randomDouble + 0.5);but I dont know how to hard code a seed using this.
    thanks.

    ryanj318 wrote:
    I tried that, and the problem is that I get the same random number every time (in this case I get 1 every time).Then you must be creating a new Random every time.
    To be more clear on what I want, I am generator 20 numbers, and I want a random distributions of 1's and 0's, but I want to get the same distribution every time I run the program. Like if I get 13 1's and 7 0's then I want to get that every time. Can I do this? Right now, I will end up with either 20 1's or 20 0's.
    ThanksCreate a new Random once, probably as a static member variable, but possibly just at the start of that method. Seed that Random with the same value every time it's created, and you'll get the same sequence every time you use it.
    BUT, if you create it, then use it, then create, then use, and repeat that 20 times, then you'll be getting the first number of the same sequence 20 times.
    By the way, to you want 1/0 or true/false? If the latter, I believe Random has a nextBoolean method.

  • Defining a lower boundery for a random number Generator

    Hi,
    I am using the code:
    Random rand = new Random();
    int x = rand.nextInt(50);
    to generate a random number between 0 and 49
    However I now need to only select a number between 20 and 49
    Is there any way to give the random number generator a lower boundery as well as an upper boundery ??
    Thank you
    Craig

    example:int x = rand.nextInt(30) + 20;Will generate a number between 20 and 49.

  • Method for a random number generator???

    I need a method to generate a random number between zero and X, X being a variable set by my program. The only method I can find is Math.random(), which generates a number between 0.0 and 1.0. (Of course, I can multiply to make it an int). Can you help me out?

    I dont know if this will help not but you could do this:
    RandomNum = (int)Math.floor(Math.random() * X);
    I think that should generate your random number between 1 and variable X
    Regards,
    Carl

  • No support for hardware techs

    I am an independent Apple-Certified Desktop and Laptop Technician -- independent in that I do not work for an Apple Authorized Service Provider (Apple will not authorize my company because we provide primarily outcall services). As such, I do not have access to GSX or Apple support services where I can bounce particularly knotty problems off other knowledgeable techs. Instead, I am told, "you can always use the public Apple discussions forum."
    Unfortunately, the discussion forum is largely organized around OS releases and software products. Although there are topics organized around hardware platforms, the topics inside those are often not amenable to hardware issues.
    For example, I am having a problem with an eMac whose drive reads DVDs but not CDs, and a replacement drive shows the same behavior. I had to post this in the eMac section under "Using DVDs." I was told that topic mostly deals with operational issues and their standard response to a hardware problem was "bring it to an Apple technician."
    Would you consider establishing a forum area for repair technician issues?

    • Employ at all times a minimum of two fully certified technicians (ACDT/ACPT) as defined by Apple, who are directly responsible for Apple equipment repairs conducted by the AASP
    Hm. This is new. The "two" requirement wasn't there when I last went through the gantlet.
    As I stated, that information is not current; I don't see how it could have changed though.
    • Maintain a suitable workshop space which complies with Apple’s standards and local Health and Safety regulations
    And this was Apple's sticking point. "Suitable" means open and staffed during business hours, located in a commercial zone, having a reception area separate from the repair area, and a number of other one-size-fits-all requirements that must sound good to some fellow from urban/suburban California, but don't make much sense for a repair facility that services 1,100 square miles of desert dwellings, outposts, and trailer parks. Roughly a third of my clientele don't or can't drive, mostly due to age or infirmity. Another third (well-off retirees) won't drive, and expect to be served at home. The rest just prefer home service. To establish and pay for such commercial space would force my fees much higher without providing any corresponding benefit to my customers.
    Call them again. Explain the situation. If need be, go up the managerial scale until someone who has the authority can decide one way or the other.
    I covet several important advantages that I can get only through AASP accreditation. One, being able to get original Apple repair parts at Apple prices. Two, having a source of telephone assistance for knotty repair problems. But most importantly, it would mean being able to perform warranty work and receive reimbursement from Apple. You've no idea how frustrating it is to have to tell a customer, "You have AppleCare and your machine is under warranty? Great, that means your repair is free! The bad news is that now I can't do it, and you'll have to drive 60 miles each way to the Apple Store, twice."
    I have developed extremely good relationships with some AASPs who are in my area. Take them out for drinks, Christmas Cards, a round of golf.. etc. As such, whenever one of my clients has a hardware issue that's covered by warranty, AppleCare or some repair extension program, I simply take their Mac to one of those AASPs local to me and I know that they will turn it around as quickly as possible. They're happy, I am happy and, more importantly, my client is happy.
    Are there any AASPs that are close to you? If there are, don't look at them as competitors. Try and build a relationship with them till you have successfully gained your AASP accreditation.
    Kryten

  • OWB support for ISO Week number?

    Is there any way to get the Time dimension wizard to support the ISO standard for Year and Week numbering (formats IYYYY and IW)?
    I need to set up a time dimension for our data warehouse and our company uses the ISO Year/Week numbering schemes (see http://en.wikipedia.org/wiki/ISO_8601) if you don't know what these are.
    Failing that I can try to create my own but it looks like a tedious process calculating all of the durations, start and end-dates.
    Any guidance would be appreciated!

    hi,
    thanks - i did check the docs :)
    the problem is that Calendar's idea of what the first week in the year is differs from the ISO standard
    the problem is that the ISO standard defines the first week of the year as that containing the first Thursday (ie some days may become part of the previous year's weeks)
    and Calendar defines it as the docs state - so to change the value returned would mean you having to change the "FirstDayOfWeek" or the "MinimalDaysInFirstWeek" - which (without checking recently) I think the ISO standard also defines so you can't safely change these
    I might raise a RFE against Calendar about this in a week or two since it seems quite important?
    thanks,
    asjf

  • 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);
    }

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

Maybe you are looking for