How do I create a random number generator?

I know I've done it before...but I can't remember quite how to get it going. I'm creating a math tutor program, which generates two random numbers and asks the user to add them, and if the answer is right they get a message that gives props and if they get it wrong they're told they got it wrong.
I can't get too far because I've forgotten how to make the number generator, so what exactly do you put in to get it?
import java.util.*;
public class AssignmentFour3 {
     private static Random integer = new Random();
     double number1 = 0;
     Random string1 = new Random();
     }

DrClap wrote:
Generally I don't write my own random number generator. I just use the java.util.Random class.I read it as though that that is what he was going to use, but wasn't able to read the API docs to figure out what methods to use. ;-)

Similar Messages

  • How can I create a random number and letter in a text field...

    Hi All,
    I am using application express. I want to get a random number and letter for a text field but not sure how to do this. Say I have a licence form and I want to get the licence number automatically when user wants to create a new licence and it needs to be unique. The format I am looking for is - HQ2631 something like this.
    I am thinking I have to create a trigger but not sure how to go about this....
    advanced thanks,
    Tajuddin

    Something to play with:
    Your method can generate 26 * 26 * 10000 different licence_ids
    Generating one million ids takes 20 seconds but produces between 70000 and 80000 duplicates and is rapidly getting worse (if that is something over 7%, doubling the ids generated that grows to something under 30%)
    Just see if you can live with that.
    select sum(collisions) all_duplicates,count(*) distinct_duplicates,max(collisions) max_multiple
      from (select licence_id,count(*) - 1 collisions
              from (select DBMS_RANDOM.STRING('',2) || trunc(DBMS_RANDOM.VALUE(1000,9999)) licence_id
                      from dual
                     connect by level <= :to_generate
             group by licence_id
             having count(*) > 1
           )Regards
    Etbin

  • Is there a way to create a random text generator in AE 4 ?

    Hi all,
    I'm a new user of an old version of After Effects 4.1 on Windows 7.
    I just gained the help on this forum to create a digital clock countdown with the Numbers Effect and the Timecode 30 setting in AE 4 and I noticed that there is a random numbers generator in that effect too.
    But now I'm in the Text Effect and I'm able to put my text/title on the solid layer in a composition and apply some MM scripts to the text... mainly I've just been able to use the 'Blink' script and manipulate that script a little to make it flash faster or slower.
    Since AE 4 cannot use .jsx scripts or Expressions, I guess I'm limited to MM scripts (which I've been searching for) and the built-in plug-ins and effects... but I can't find a random text generator... like where the text scrambles as if it is trying to break a code.  This effect that I'm trying for would be similar to a scrambled text effect generated in Swish or other FLASH text effect generators.
    So if anyone knows how to create a scrambled or random text effect in the old After Effects 4.1, please let me know.
    Thanks allot,
    digi

    Thanks guys,
    Yes, I'm using AE 4.1, per my explanation in my other posts about the timecode effect and codecs.
    Since there is a built-in random number generator in AE 4.1 that is part of the Numbers Effect, I thought there may still be an after market Effect, plug-in or mm script for a random text generator.
    I've been searching the web, but its a big place.
    Thanks,
    digi

  • Random number generator. Even and odd numbers

    I have a problem.
    I have a random number generator, it goes from 0 to 20, I need to have two indicators, one will show how many numbers are pairs, and how many are not.
    I tried to use the decimated 1D array, but since those numbers are random, it doesn´t work for me. I´m new with LabView, and I don´t know if there is some other way to make it work, I need some help, especially with some examples.
    Thank you so much.
    Solved!
    Go to Solution.

    RavensFan wrote:
    Spoiler (Highlight to read)
    Create the array.  Use quotient remainder to divide by 2.  Now you have an array where all the odd numbers are now 1, and all the even numbers are now 0.  Sum the array and you have the total number of odd numbers.  The number of evens will be the length of the array divided by the # of odds.
    Create the array.  Use quotient remainder to divide by 2.  Now you have an array where all the odd numbers are now 1, and all the even numbers are now 0.  Sum the array and you have the total number of odd numbers.  The number of evens will be the length of the array divided by the # of odds.
    Haha I lost sight of the fact that he was looking for the amount off odds and evens.  Good one.
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

  • 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 Generator issues

    Ok so I have an issue. I'm supposed to create a GUI app that has a frame that contains both a button and a textfield. When the button is pressed then a random number between 1 and 10 should appear in the textfield. I've got an illegal start of expression on line 49 which is the last private void...
    So what have I done wrong?
    * randomnumber.java
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Random;
    public class randomnumber extends JFrame
         Random randomObject = new Random();
      // declare controls used
      static JButton startButton = new JButton();
      static JTextField startTextField = new JTextField();
      public static void main(String args[])
        new randomnumber().show();
      public randomnumber()
        // frame constructor
        setTitle("Random Number Generator");
        getContentPane().setLayout(new GridBagLayout());
        // add controls
        GridBagConstraints gridConstraints = new GridBagConstraints();
        startButton.setText("Generate a Number");
        gridConstraints.gridx = 0;
        gridConstraints.gridy = 0;
        getContentPane().add(startButton, gridConstraints);
        startButton.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
            startButtonActionPerformed(e);
        startTextField.setText("");
        startTextField.setColumns(15);
        gridConstraints.gridx = 2;
        gridConstraints.gridy = 0;
        getContentPane().add(startTextField, new GridBagConstraints());
      private void startButtonActionPerformed(ActionEvent e)
        myInt = randomObject.nextInt(11);
        startTextField.setText(String.valueOf(myInt));
    }Edited by: Hessmix on Oct 17, 2007 6:15 PM

    public randomnumber()
        // frame constructor
        setTitle("Random Number Generator");
        getContentPane().setLayout(new GridBagLayout());
        // add controls
        GridBagConstraints gridConstraints = new GridBagConstraints();
        startButton.setText("Generate a Number");
        gridConstraints.gridx = 0;
        gridConstraints.gridy = 0;
        getContentPane().add(startButton, gridConstraints);
        startButton.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
            startButtonActionPerformed(e);
        startTextField.setText("");
        startTextField.setColumns(15);
        gridConstraints.gridx = 2;
        gridConstraints.gridy = 0;
        getContentPane().add(startTextField, new GridBagConstraints());
      }//<< Add a brace here
      private void startButtonActionPerformed(ActionEvent e)
        myInt = randomObject.nextInt(11);
        startTextField.setText(String.valueOf(myInt));
    }Did you add that brace?

  • Help for random number generator???

    hi there can anyone how to make simple random number
    generator for slot machine , formula for chances in probability ,
    or simple random number generator for slot machine , thanks
    :)

    actualy the accurate RNG for slot machine ?? any idea?

  • Help: JSP Random Number Generator

    hello every one,
    Im trying to generate a random number using currentTimeMillis(), in Jsp, can you help me out and advice me how can this be done please.

    First you say you want a random number, then you say you want a unique one. Which is it?
    Random numbers do not normally guaruntee uniqueness.
    is there away i could use the currentTimeMillis(), What would you use it for? System.currentTimeMillis() is commonly used as a seed for a random number generator. The java.util.Random class uses it like that - take a look at that API link.
    Or if its a homework question state the exact requirement - I'm guessing here.

  • Random NUMBER generator help..

    Hi all,
    i'm having issues with my random number generator i'm trying to fill my array with random numbers but i keep getting it filled with zeros.... can any one tell me what i'm doing wrong i can;t figure it out..
    for (int i =0; i < 100; i++){
                        int x=(int) (Math.random());
                        data[i] = x;
    }

    From the API "Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0."
    So casting the value to int is always going to result in a zero value.
    You need to multiply by a value that is one larger than the value you want to be your maximum. For example:
    int x = (int)(Math.random() * 100);
    should create a random number from 0 to 99

  • Does Labview have a Random Number Generator for U16 with a periodicity greater than 64 Million instances of U16words and one with SEED as the connector?

    We are doing some testing that requires 64MegaWords be written to our DSP memory  with random values to do a validity check and without repeating sequences with using the previous value as the seed for the next and us passing it the initial seed.  The dice one doesn't meet that criteria, and I was not sure how the continuous random number generator parameters work and if any of them would meet this criteria. Anyone have any information that might help?
    Thanks,
    Sue

    Hi suem,
    There is no reason why you couldn't simply write a pseudo-random number generator by yourself. Simply select a random number algorithm you want to use and implement it in LabVIEW. You do not need to interface code written in another language in order to implement a pseudorandom number generator. If you have a DAQ card or something, you can also use inputr noise or some other hardware soruce to generate real random numbers. For that also LabVIEW is an excellent tool.
    Tomi
    Tomi Maila

  • Uniform random number generator

    anyone of u know how to generate UNIFORM RANDOM NUMBER GENERATOR that has serious faults ?

    jwenting wrote:
    uj_ is right (never thought I'd say that).
    ANYTHING "uniform" is by definition not random.Well, the correct term is "random numbers from a uniform distribution". And there certainly exist such generators (athough they're pseudo-random of course).
    I lost my temper because I've spent considerable time helping sosys only to realize he's a notorious cheater. Sosys claims to be a college student attending a CS class. With the knowledge, or rather lack thereof, he's displaying he must've cheated systematically for a long long time. I'm quite liberate at helping people with their homework but I won't help a leech become a programmer.

  • How do i create an imessage number

    how do i create an imessage number, and can i send messages to non iphone/ ipod numbers

    planb77, The is (or at least was) an app that added the Messages app to Snow Leopard. I had that before upgrading to ML

  • How can one create a paint color generated from a photo using Kuler?

    How can one create a paint color generated from a photo using Kuler?

    The best way to remove a pattern is to use a Fast Fourier Transform.  There's a free plugin (as well as examples and instructions) here:
    http://dl.dropboxusercontent.com/u/6795661/4N6site/improc/fftplugin/examples.htm
    Using the plugin requires editing the individual colour channels, which PSE does not natively allow.  You'll need the reasonably-priced Elements+ addin:
    http://elementsplus.net/
    Here's a crop at 100% of the result I got:
    The pattern is much reduced.  With some experimenting, you can probably do a little better.
    Ken

  • How can I alter the random number seeding in Labview?

    Is there a way to force a particular seed or dynamically reseed the random number generator in Labview?

    You could use a flat noise generator with one sample.
    It is able to be seeded.
    Tim
    agolovit wrote:
    > Is there a way to force a particular seed or dynamically reseed the
    > random number generator in Labview?

  • Java random number generator

    Hi does java have a random number generator. If it does can you point me to it please. Thank you.

    you can use "java.Math.random()" this function returns a value which is greater than or equal
    to 0.0 and less than 1.It returns a double value,so you can multiply by 10 and cast it to int,so that it
    can produce numbers between 0 & 9.Yes, you can do that. But, as stated before, java.util.Random has methods that are easier to use for random int values than using java.Math.random is for random int values. It all depends what the OP wants. The OP hasn't come back with additional questions, or to say that he found his answer. So, we don't know whether he has his answer (he has several options now!) or not. :)

Maybe you are looking for

  • SDD + HDD (With bootcamp) Setup

    Hi guys i need help setting up bootcamp with my ssd and partitioning my hdd.  So i already bought my converter for HDD to optical bay. what i need to know now is how to set all of this up Heres my plan 1. Install SDD to the main drive, move HDD to th

  • Sequencing Java

    Hi all I googled how to sequence java using app-v 5 however its a rather confusing as one article will talk about how to use the deployment. properties file another will talk about using power shell to use only the current version of java in the bubb

  • One logical column used twice in the prompt

    Hello Gurus, I have a report which is presently showing Sales across country COuntry Name | Sales USA 100$ Japan 100$ Country NAme | Statename 1 | Satename 2 | Usa 50$ 100$ But State 1 and state 2 are one logical column called state in the RPD. User

  • Restore source system

    .after the Client copy to the source system I want to  restore the source system what hapens to the objects which already migrated to BI 7.0  and all the transformations and DTP's created. Partner profile and IDoc settings

  • Install Oracle 10gR2 on Windows x64

    Is this possible to install Oracle 10gR2 on Windows 2008 x64 ? I though that there aren't any difference between 2003 and 2008, but during reading this presentation: http://www28.cplan.com/cbo_export/PS_S291788_291788_176-1_FIN_v2.pdf (login: cboracl