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.

Similar Messages

  • 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                                      

  • Very strange iTunes behavior, please help!

    Every once in a while, I will notice a song in my library that has a time listed that I know is shorter than the song's actual length (for example, a song I know to be 5 minutes+ will be listed in the library as 1:37). When I play the song, the time adjusts to the proper time, so that is not the problem. However, if I sync my iPod, iTunes will only sync the time listed (1:37 in the example) to the iPod! It seems to be 100% random in the songs it effects and time it changes it to. Please help me out!
    Edit: I also forgot to mention, it will make songs longer also, but that is not as much of a problem because it will go on the iPod, show the "longer" time and then just go to the next track once the actual music is over
    Message was edited by: zellin

    I only have a 'CD Info.cidb' file in the preferences.
    Couldn't hurt to drag them on the desktop too, I suppose.
    Just don't trash them yet.
    The article I referenced to, should have read as here
    Forgot 1 character and didn't check it with 'preview' (this one I did)
    M
    17' iMac fp 800 MHz 768 MB RAM   Mac OS X (10.3.9)   Several ext. HD (backup and data)

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

  • Getting randomly added please help.

    Hello..
    I would like to ask something..
    Since yesterday i started to being added by many random people and they 
    are asking my on skype if i wanna cam 2 cam.. i dont know where they come from?
    i haven't register on any dating sites and stuff and this is annoying.. what can i do?
    thx.

    Hi, Karlitaki, and welcome to the Community,
    Despite the popularity of doing so, I recommend never linking Skype to any social media account such as FaceBook.  Hopefully, your account was not added to a "friend request" website without your knowledge.
    Please see this FAQ article:  https://support.skype.com/en/faq/FA34447/what-should-i-do-if-i-see-abusive-behavior-on-skype
    Regards,
    Elaine
    Was your question answered? Please click on the Accept as a Solution link so everyone can quickly find what works! Like a post or want to say, "Thank You" - ?? Click on the Kudos button!
    Trustworthy information: Brian Krebs: 3 Basic Rules for Online Safety and Consumer Reports: Guide to Internet Security Online Safety Tip: Change your passwords often!

  • 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

  • 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

  • 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()

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

  • Probook 4540s view rotates (almost) randomly. Please help

    Hi, this is a Probook4540s. I have recently updated to Windows 8.1. The view on the display started rotating upside down when I lean the laptop backwards and forwards, when I click buttons on the toolbar and sometimes when I click the close / minimize buttoms.
    I can rotate the view to the normal view by leaning the laptop forwards or by clicking alt gr + upper arrow (only if the keyboard is in Romanian. It's very frustrating, since I hold the laptop on my la and make slight mooves.
    How do I make it stop?
    any suggestions will be appreciated.
    Many thanks!

    Hi AlinaBulina,
    Your ProBook 4540s is a commercial product and to get your issue more exposure I would suggest posting in the commercial forums. Here is a link to the Commercial Notebook forum.
    Thank you,
    Please click “Accept as Solution ” if you feel my post solved your issue.
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    Thank you,
    BHK6
    I work on behalf of HP

  • WRT160N V3 Xbox 360 trouble router randomly resetting PLEASE HELP

    For Christmas 2009, I received the wrt160n v3 Linksys by Cisco router. This router worked fine until about early November of 2010, when I would turn on my xbox to play a multiplayer game, and the router would randomly reset and i would lose my connection, as well as all the computers connected to the router would lose their connection to the internet. I actually sent that one back to linksys through an rma and received a new one of the same model and version, and I am still having the same problem. The router even resets when I am not on my xbox, simply just on my laptop. It is incredibly frustrating and cannot seem to find any help on the internet. Does anyone else have this problem? Are there any solutions? Is it my router or could it be my xbox screwing everything up? Any help is welcome, thank you very much

    nevermind my router just reset while playing xbox. mtu is 1365, i unchecked that box, and opened my nat type, and it still reset. im starting to get extremely dissatisfied with your products

Maybe you are looking for

  • Follow up question...

    I just purchased a Airport Extreme from the Apple Store yesterday. I purchased it to extend/share my iPhone 5 hotspot. I have figured out how to have AEBS join my hotspot, but it does not seem to have access on the Ethernet ports in the back?? This i

  • Creating stills in photoshop cs2 for 16:9 HDTV

    Hi, I've been reading posts regarding creating stills and still need some clarification. I'm from a print world, so dealing with square pixels vs. non square, hdv, vs dv widescreen is all a bit confusing.... I've been to this link: http://www.fcpbook

  • MMD Hard Drive issues

    I attempted to install a new PATA hard drive and was never able to get it to be recognized or mount, no matter I gave up on that and went back to my original configuration to find that my 3rd small drive was now unreadable. I erased that and remounte

  • Using a 9- to 4-pin adapter / firewire noise

    Whenever I record an instrument with a pickup, I get a wind-up sound every few minutes; a high-pitched whine that I can only assume is from one of my hard drives. I know that the sound isn't coming from being in close proximity to the internal HD. I

  • IPlanet 4.1 - Which Service Pack Version?

    Hi, we have IPlanet 4.1installed and wanted to upgrade to the actual service pack. Can sb tell me how i can determine which service pack is installed now? And .. which service pack is the most recent (SP9 or SP12)? Thanx in advance .. Markus