Random numbers..please help

hi,
this is probably so basic.. but dont know it
if i have a statement like this
int number = (int)(Math.random()*12);what random numbers will i get?
is it from 0 to 12 or 1 to 12 or what.?
basically i need to get numbers in a range say 1 to 13
thanks

I believe that will return numbers from 0 - 11. If you're looking to get numbers 1 -13, then try something like:
int number = (int)(Math.random()*13+1).I would recommend putting your code into a for loop that runs a hundred times and look at the results. There is another class Random (in java.util.Random) that also generates random numbers - might want to check that out.

Similar Messages

  • Need Help with random numbers, please help

    Hi guys;
    I need your help for a school project. I need to generate a random number from 1.0 to 2.0. How would I do that?
    Regards,

    http://java.sun.com/j2se/1.3/docs/api/java/util/Random.html#nextFloat()

  • I spend a long time to try to sync my itunes music on my ipod 160 GB Classic, but after waiting so long get a pop up message that itunes stop syncing because of error 46, some times giving me 58, 1469, and many other numbers, please help macbook pro

    i spend a long time to try to sync my itunes music on my ipod 160 GB Classic, but after waiting so long get a pop up message that itunes stop syncing because of error 46, some times giving me 58, 1469, and many other numbers, please help am using macbook pro

    That is precisely what my mid-2010 MacBoook Pro 13 was doing before the drive finally died after an Apple Genius rebooted it a dozen or so times. I have since read about the exact same thing happening to others, including a writer for The Atlantic magazine who had never had an issue with a Mac before. Do a back-up ASAP to make sure you don't lose anything and see about replacing the HDD. It is only about $140 for a new drive. The real issue is if you lose your data, too. So, make sure you do that back-up!

  • When ever i touch for example appstore it touches safari. i press home button the my phone does what ever it wants, like goes to settings and presses random stuff please help. :(

    when ever i touch for example appstore it touches safari. i press home button the my phone does what ever it wants, like goes to settings and presses random stuff please help. :(

    Try restarting it. If this does not work, then hard restart it which is holding the power and home button until the product ***** off. If this does not help either, plug it into the computer and restore it. Make sure you back up the device before you restore it though! Here are instructions on how to restore and back up an apple device. http://support.apple.com/kb/ht1414

  • My iPod touch 2nd generation keeps turning the volume up and then turns off, by itself randomly. Please help!!, My iPod touch 2nd generation keeps turning the volume up and then turns off, by itself randomly. Please help!!

    my iPod touch 2nd generation keeps turning the volume up and then turns off by itself randomly. Please help!

    Try the standard fixes in order:
    - Reset:
    Reset iPod touch:  Press and hold the On/Off Sleep/Wake button and the Home
    button at the same time for at least ten seconds, until the Apple logo appears.
    - Restore the iPod from backup via iTunes
    - Restore the iPod to factory defaults/new iPod
    - Make an appointment at the Genius Bar of an Apple store.

  • T5i takes random pictures, please help.

    Does anybody have this problem? My T5i takes random pictures. I have a battery grip so not sure if that would cause any issues. Basically, I have my camera on, I take a picture and move camera back to my side and I hear shutter go off. I raise camera up to take a picture and shutter goes off - taking a picture. It happens sometimes not all the time. My battery grip is "OFF" so I know I'm not accidently clicking on the shutter. This is so annoying eerr!! Please help. 

    Hello Aktors,
    As another user had suggested, this may be an issue with third party hardware.  We would want to check to see if the issue persists without the third party hardware attached.  Also, try another lens on the camera if possible too.  This will help us and others, troubleshoot this issue.
    Did this answer your question? Please click the Accept as Solution button so that others may find the answer as well.

  • IPod Touch Turns Off Randomly. Please Help!

         I got my iPod Touch 5th generation about 34 days ago. In the past 2 or 3 days my iPod has been shutting off randomly. I would be using an app, and it would be unresponsive, and turn a blue vertical lines on the top of the screen. I then have to use the sleep/wake button and the home button to turn my iPod back again. I bought it at Walmart because there is no local Apple store near me. It sometimes gets hot and I have turned off location services to make it cool down a little bit. I can trust Apple products usually, but this is out of the normal for me. Please help!       Thank You very much in advance.

    Try:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings      
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                                
    iOS: How to back up                                                                
    - Restore to factory settings/new iOS device.             
    If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar                                      

  • IPod starts automatically and at random! Please help!

    I've looked at all troubleshooting issues on Apple's sight, but find no references to my problem.
    My 5G iPod (2 months old) starts automatically at an undefined time and continues running until I either shut it off or the battery runs down.
    I've tried every setting option to stop the auto-start but nothing helps. I've tried resets and iPod software updates. I've used the lock at top to prevent accidental keypad startups. Nothing helps.
    Can someone please help?
    Toshiba laptop   Windows XP  

    Thanks A LOT! I didn't realize that my alarm clock was on. I was about to pull out what litlle hair I had left.

  • Multithreading working randomly. Please Help

    Ok so I am in process of making a game on java (and no I do not want to use pre made engines and so forth).
    So I made a JFrame
    Created a timer and
    timer = new Timer(SPEED, this);
    timer.start();
    where SPEED is 15 (roughly 60 frames per sec I hope)
    and I have a method
    public void actionPerformed(ActionEvent e)
              hero.move(wall);
              for(int i=0; i<wall.length; i++)
                   wall.setX(wall[i].getX()-hero.getXVector());
              repaint();
    now wall is an array of objects that have x and y coordinates and a width and height
    This is my move methodpublic void move(Wall walls[])
              standing = false;
              for(int i = 0; i<walls.length; i++)
                   if(walls[i].getTopLeftX()<this.getTopRightX() && walls[i].getTopRightX()>this.getTopLeftX())
                        if(walls[i].getTopLeftY()<this.getBottomLeftY() && walls[i].getBottomLeftY()>this.getTopLeftY())
                             standing = true;
                             this.setY(walls[i].getTopLeftY()-super.getWidth()-1);
                             dy=0;
                             System.out.println("Standing");
                             return;
              if(!standing)
                   dy = dy + GRAVITY;
                   super.setY(super.getY()+(int)dy);
                   System.out.println("Not standing");
    Now when I run the program it prints out
    Standing
    Not standing
    Not standing
    Not standing
    Standing
    Not standing
    Not standing
    Not standing
    Standing
    Now I do not understand, when object is standing on ground, why 3 times it says notstanding, and once it says standing.
    Please Help someone
    Any help will be greatly appreciated.
    Thanks a lot to all in Advance                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Note: This thread was originally posted in the [Java Programming|http://forums.sun.com/forum.jspa?forumID=31] forum, but moved to this forum for closer topic alignment.

  • Stop random numbers repeating HELP!!

    i have been trying to create ten random numbers between 0-99 without them repeating and put them into an object array. this is the code i have been trying but it doesn't seem to work.
    public static void main (String[] args)
         Random generator = new Random();
         Object[] data = new Object[10];
         int marker = 0;
         for (int i = 0; i< data.length; i++)
         int number = Math.abs( generator.nextInt() )%99+1;
         Integer random = new Integer ( number );
         for ( int a = 0; a < data.length; a++ )
                   if ( ( data[a] ) == random )
                   marker = marker + 1;
                   if ( marker == 0 )
                        data[i] = random;
                   else
                        i = i - 1;
                        marker = 0;
              for (int i = 0; i < data.length; i++)
                   System.out.println( data[i] );

    redesign your code, how is that look? :)
    public static void main (String[] args)
      Random generator = new Random();
      Object[] data = new Object[10];
      Set set = HashSet();
      while(set.size() < 10)
        int number = Math.abs( generator.nextInt() )%99+1;
        Integer random = new Integer ( number );
        set.add(random);
      Iterator iter = set.iterator();
      int j = 0;
      while (iter.hasNext())
        data[j++] = iter.next();
      for (int i = 0; i < data.length; i++)
        System.out.println( data[i] );
    }--lichu                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • TS1292 Missing Numbers please help

    HELP i HAVE SCRATCHED OF A COUPLE OF MY lETTERS OR NUMBERS
    THIS IS WHAT i CAN READ
    <edited by host>
    THANKS  LYNNE

    Hi...
    Please do not post personal information here as this is a user to user forum. I have asked for your email address and gift code to be removed.
    You can contact iTunes support with those details here:
    http://www.apple.com/support/itunes/contact/

  • My fb, n different apps keep just randomly cloising. please help.

    everytime i open up any app it doesnt matter what it is after a while it will just randomly close. i dont have any more pace on my phone to download the latest version of the software upload. please can someone help!!!

    You should delete some content on your phone, and then create a backup. Delete a couple of apps, your pictures, text messages, etc. Then create an iTunes backup and restore the device as new. This will update your device as well as resolve any software issues. Then restore from your backup.
    http://support.apple.com/kb/HT1766

  • Random behavior -- please help!

    I posted yesterday and only received one response, so I'm posting again in the hopes that someone will be able to help. This time I'm including some of the code that's giving me problems.
    This is what I wrote yesterday:
    I'm writing a Java program that schedules employees into a monthly work schedule. I'm trying to write it such that the list of employees (which is read in from file) is in a different, random order for each day of the month. This way when the program accesses the list to start scheduling people into shifts, the list of employees will be in a different order each day.
    I thought I had it, but when I execute the program, the employees show up in the exact same order for every day EXCEPT the very first day of the month. Why would the random generator use a unique list for the first day and then the same list for all subsequent days?
    In my scheduling method, I iterate through each of the days in the month, and at the beginning of each new day, I call the method that supposedly rearranges the order of the list of employees. Here's that method:
        public ArrayList makeNewEmpList()
            ArrayList temp = new ArrayList();
            while (temp.size() < emps.size())
                int i = rand.nextInt(emps.size());
                Employee doe = (Employee) emps.get(i);
                if (!temp.contains(doe))
                    temp.add(doe);
            return temp;
        }"emps" is my list of employees, and "rand" is my random generator. When I execute the scheduling method, the very first day of the month has a unique order, but every day for the rest of the month has the exact same list of employees in the exact same order.
    Does anyone have any idea why this is happening? Any suggestions would be greatly appreciated!
    Thanks again,
    Erica

    So do I need to specify that the random generator
    should only choose numbers within the range of
    emps.size() -- as I did in the original code above --
    or will it automatically choose within that range
    because I'm also giving it the list to shuffle?Check out the documentation, you'll see that it just requires a Random object. You don't have any control over how one of those works anyway. Or you can just call Collections.shuffle(emps) and it will create its own Random, which is most likely just as good.
    Also, you're saying that I can just put this one line
    of code in place of the line in which I call the
    above method in my main scheduling method? I'm not
    sure how to use the Collections class.I think so. Your description of your requirements seemed to be a description of shuffling the list of employees randomly. Again, read the documentation to ensure that it is going to do what you really want done.
    What you're
    suggesting will alter the order of the "emps" list
    itself, right? Because I was trying to create a new
    ArrayList for each time through, but I guess it
    doesn't matter if I just keep altering the orignal
    list. Yes, it will. You're right, you might have to reorganize some other code to account for that.
    Thanks so much for helping! I really appreciate it.

  • Can some one tell me how to get this imessage (i think thats what it is they are in blue) off my flippin phone because they are going to other ppl as well as ppl intended and i keep recieving msgs from randoms grrr please help

    i recently went from a iphone 3 to a 4 and when i send messages they are going to other ppl as well as the ppl they are intended for this did happen once with the iphone 3 but now its all the time i have been in settings but it's not high lighted so dont know how to get the **** thing off so i can just send normal msgs, please advise 

    i didnt have any on but i disabled it then enabled lol dunno how but i have done it i think thanks for your help there is tooooo many settings on the phone for me i was ok with the 3GS just flicking through settings again and my face time as dissapeared lol any ideas

  • My macbook constantly freezes randomly? please help!!!!!!!!!!!

    I have tried virtually everything I could. Repairing disk utility, resetting PRAM. Whenever the freeze happens all I can do is resort to forcefully shutting it down. To be more detailed, at startup I ussually hear my macbook getting louder than ussual. I even erased everything I had on the disk and It would still freeze randomly. (of course I backed everything up) I am at a loss at what to do I even struggle with connecting to the internet on it. Would upgrading to os lion resolve this?

    Upgrading will not help. First you must resolve the cause of the problem. Since you have a current backup do the following:
    Drive Preparation
    1.  Boot from your OS X Installer Disc. After the installer loads select your language and click on the Continue button.  When the menu bar appears select Disk Utility from the Utilities menu.
    2. After DU loads select your hard drive (this is the entry with the mfgr.'s ID and size) from the left side list. Note the SMART status of the drive in DU's status area.  If it does not say "Verified" then the drive is failing or has failed and will need replacing.  SMART info will not be reported  on external drives. Otherwise, click on the Partition tab in the DU main window.
    3. Under the Volume Scheme heading set the number of partitions from the drop down menu to one. Set the format type to Mac OS Extended (Journaled.) Click on the Options button, set the partition scheme to GUID (for Intel Macs) or APM (for PPC Macs) then click on the OK button. Click on the Partition button and wait until the process has completed.
    4. Select the volume you just created (this is the sub-entry under the drive entry) from the left side list. Click on the Erase tab in the DU main window.
    5. Set the format type to Mac OS Extended (Journaled.) Click on the Options button, check the button for Zero Data and click on OK to return to the Erase window.
    6. Click on the Erase button. The format process can take up to several hours depending upon the drive size.
    When the process has completed do a fresh install of OS X. Before you restore anything from your backup check out the new system to be sure you no longer have problems. If you continue having problems then most likely there's a hardware issue. You may have defective or marginal RAM. You could try removing the RAM, clean the contacts on the edge card using a clean pencil eraser. Then reseat the RAM.
    You can also try Intel-based Macs: Resetting the System Management Controller (SMC)

  • Problems with the alt key and numbers, please help major issue

    All of a sudden I am unable to use the alt key with any numbers, meaning I can't create hashes (alt 3) and bullets (alt 8), and others that I haven't missed yet. I've tried two keyboards, one wireless and one wired but to no avail. It seems to work fine for everything except 3 through 9.
    I found somebody with the same issue beforehand:
    *I have finally tracked the problem down to a problem preference file, namely this one:*
    com.apple.symbolichotkeys.plist
    *I have no idea what it's supposed to do, but it wasn't doing it right.*
    But even still, it made no sense to me, can anybody help me? This is an issue that's been disrupting everything I do on my Mac for a few days now, and not found the issue as yet.

    Feel a bit silly now! Just sorted it myself, had a look around my hard drive, and deleted the com.apple.symbolichotkeys.plist file, and restarted, when I started up and tested it my ¡€#¢∞§¶•ªº keyboard alt tab seemed to work!
    For future reference, just do this and restart afterwards:
    [YourHardDrive]>>Users>>[YourUserName]>>>Library>>>Preferences>>>com.apple.symbo lichotkeys.plist>>>Delete that>>>Restart your Mac and you've fixed it.
    Cheers anyway!

Maybe you are looking for

  • Item text inconsistency for multiple item text in CRM Billling document

    Hi Experts, I am facing problem in adding item text in CRM Billiing document in Web UI.There are 3 line items in my billing document and their item text gets determined from Billing due list items but there is a requirement to change the item text at

  • Foreign trade data: import procedure determination in PO

    Hi, The import procedure field in my PO is sometimes filled in sometimes not. When I use PO-Type ZFA I get my import procedure automaticaly filled. When I use PO-Type ZRP i do not get it filled in. Although the Article, supplier and plant are exactly

  • Why won't 110 min video not fit DVD when using Compressor Best 120 min

    I have a standard DV video lasting 110 minutes. I have exported it as a DV clip and imported that clip as an asset in DVD Studio Pro 4. Build fails with a not enough room on the output media message. I have also exported from FCP using Compressor set

  • OSM orders getting stuck at particular task

    Hi, I am facing problem with OSM cartridges . Orders are getting stuck at particular task. I can see in OMS web client that particular task is still in Accepted state whereas it should have gone to completed state and proceeded to next task. I can al

  • Decreased min free swap space

    Hello everyone, due to technical problems, in 07/Dic/2005 we had to replace a disk in one of our cluster server of SAP R/3 Enterprise. We also increased its level security from RAID 0 to RAID 5. But today we have detected than since that moment, the