Is there an easy way to select Items randomly from a data structure?

Put simply, I want to implement a "bag" data structure. So, when i select an item I don't know which one i'm going to get. I want to be able to select all the items once (so no replacing of items i.e. selecting the same item twice in one session).
I can think of ways to implement it using random number generators and the like but does anyone know of a simple datastructure that will encapsulate this "bag" functionality and make my life simple. Hash tables maybe? Any pointers appreciated.
Chris.

I don't think there is anything like this in the collections framework but writing one as an extension of a vector could be simple. Something like:
public class Bag extends Vector {
  private Random _random = new Random();
  public Object pickRandom() {
    return this.remove(this._random.nextInt(this.size()));
}To add objects to the bag you just use the add(Object o) method (specified by the List interface, implemented by Vector). To "grab" one just call pickRandom().

Similar Messages

  • Is there an easy way to select complimentary colors from within Photoshop?

    Is there an easy way to select complimentary colors from within Photoshop?
    Is there a tool like Kuler for Photoshop?
    Kind regards,
    Michael
    Learn how to do meditation

    See attached image... I have PS CS5.
    Is there a way from the color picker or using color libraries to pick shades, complimentary, tetradic or triadic colors?

  • Is there an easy way to upgrade your OS from 10.5.8 to 10.6

    is there an easy way to upgrade your OS from 10.5.8 to 10.6?
    Thanks for your help
    desmoutis

    Welcome to Apple Support Communities
    To upgrade, first buy Snow Leopard > http://store.apple.com/us/product/MC573/mac-os-x-106-snow-leopard
    It's recommended to make a backup of your files. If the upgrade fails, you will lose data. After making the backup, insert the DVD and follow on-screen steps to upgrade.
    That disc will install 10.6.3, so open  > Software Update, and install OS X 10.6.8

  • Is there an easy way to eliminate duplicate tracks from iTunes on a mac?

    All of a sudden I have over 6,500 duplicate tracks in my iTunes.  Not entire albums but many tracks from an album are duplicated.  Is there an easy way to get rid of these tracks or do I have to do this one by one?  Also why would this be happening? I have "Keep iTunes Media Organized" checked as well as "Copy files to iTunes when adding to library".

    It is hard to say why.  iTunes is unlikely to do this all its own and there is probably something you did like add a folder that is not part of the current media collection thinking it needed adding, but it had already been added in the past.
    There is no simple, universal panacea for duplicates.  You can try some of the suggestions below.
    How to find and remove duplicate items in your iTunes library - http://support.apple.com/kb/HT2905
    http://dougscripts.com/itunes/itinfo/dupin.php (commercial)
    Posts by turingtest2 about different types of duplicates and techniques- https://discussions.apple.com/thread/3555601 and https://discussions.apple.com/message/16042406 (Note: The DeDuper script is for Windows)
    Frankly, I would do it manually.  As you can see from turingtest2's post, some duplicates are not really duplicates and I would rather do it manually than discover that a script had removed my only copy of a file (yes, I have backups but I may not notice for a year or so a file is no longer there, by which time I would have overwritten the backup because I do not have drive space for storing a year's worth of weeky iTunes backups tens of GB in size).
    I would also review how you add media to iTunes.  It should not be producing all that many duplicates.

  • Is there any easy way to compare LIKE Addresses from one table, which contains 3rd party data, to another table, our database source

    We have a 3rd party that is supplying us data and we need to compare the addressing between the 3rd party data to our source database addressing. I'd like to make it somewhat flexible meaning I'd like to somehow use the LIKE comparison rather than comparing
    the exact address values. (I have noticed that the 3rd party addressing sometime has a leading <space> at the beginning of the address...why I'd prefer to use LIKE)
    Is there any easy way to do this? Or does this dictate using a CURSOR and processing through the CURSOR of 3rd party data and plugging in the address LIKE as dynamic SQL?
    Please let me know your thoughts on this and I appreciate your review and am hopeful for a reply.

    Yes, it's possible and there are a variety of options but it's may not be for the faint of heart.
    The last time I did it, I ended up taking several passes at the data.
    1st pass was a straight up comparison with no modifications or functions.
    2nd pass was the same but with all special characters removed.
    3rd pass involved splitting the numeric portion of address and comparing just the street numbers and used a double meta-phone function (kind of like a soundex on steroids) to compare the street names.
    Jason Long

  • Is there an easy way to move my playlist from one computer to another?HELP

    I recently got my own private computer and wanted to move my itunes playlist from my old computer to the new one. I downloaded Itunes 8 to my desktop but couldn't seem to get my playlist. i ended up trying to burn all my songs onto discs but i ran out of cds!! there has to be an easier way! can some one PLEASE help me!?
    Message was edited by: jackpot!

    Hi. We just got a new laptop and did this (thanks to Chris CA!): Note this was from a Windows/XP to a Windows/Vista.
    "On your original computer (XP), go to /My Documents/My Music.
    Select the iTunes folder and drag it to your external drive. * buy a flash drive instead of using cds *
    Install iTunes on the new computer (Vista).
    Launch iTunes and let it do it's stuff.
    Quit iTunes.
    Connect the external drive.
    Select the folder on the external and drag it to /Music on the C: drive.
    It should ask if you want to replace the items on the C: drive.
    Select Yes.
    When it's finished, launch iTunes and everything should be there."
    Hope this helps!

  • Is there any easy way to migrate painter reports from 4.7 Enterprise to 6.0

    Dear All
    We are being upgraded from 4.7 Enterprise to ECC 6.0 . The issue that we are facing is that company has more than 200 report painter reports ( on special ledger)  and I was wondering if there is any easier way to migrate it to ECC than redoing the whole work. What I mean to say is that, is there any tool/program/tcode that we can use for copying/editing purpose of the reports in ECC 6.0 to be based on flex ledger.
    Thanks

    Hello
    Why do you need to transport the reports?  Upgrade to 6.0 should keep your
    old reports from 4.7.
    In any case transaction GR57 allows you to export them to local file in C:\ and GR58 will import them. I have tested between systems of different releases and
    it worked correctly.
    Regards
    Javier

  • Is there an easy way to get GPS coordinates from Maps.app in Mavericks?

    My DSLR doesn't have a GPS built in, but I like to Geo-tag some of my photos. I usually just take a pic with my iPhone and then copy the geo data (GPS coordinates) and paste into the photos (in Adobe Lightroom). Unfortunately, I didn't have my phone with me. I have the location stored as a bookmark in Maps, but I don't see any easy way to just pull coordinates.

    Hi,
    I am doing the same thing too. I have to call my reports thru menu. I tried web.show_document in my menu and it works. I also added paramform=yes and it gives the report parameters, but I want to give the user the choice of format for the reports. eg. pdf, html, excel, etc. instead of hardcoding it.
    Could you please give me some idea on how can I do that??
    Thanks.

  • Is there an easy way to download my music from the iCloud to iTunes library on my new PC desktop so I can sync my iPod?  I have iMatch and cannot figure out how to do it in one fell swoop rather than by downloading each song, which will take forever!

    Hi,
    I have taken over my son's old PC desktop tower as it has more memory than my old PC.  I installed iTunes on it and have accessed via my iMatch account my music library that's in the iCloud.  I need to download it to the iTuned library on the desktop so I can sync my iPod.  I can only see how to do it song-by-song, which will take forever for my almost 5000 songs.  Is there a way to dowload the entire library in one fell swoop, letting it download without me having to do each song individually or monitor it?
    Thanks,
    RSG

    Select all songs ctrl A, right click - Download.

  • Is there an easy way to move multiple icons from one screen to another?

    I have multiple screens on my iphone 5c display.  I want to move multiple icons at the same time from one screen to another.  Is there a way to do this?

    You could put them all in a single folder and move the folder to another screen.

  • Is there an easy way to suppress debug messages from plugin.jar?

    When using the plugin.jar library (included in JRE 1.4.2 and 1.5)
    my Java Console is riddled with tons of debug messages like:
    <<< ProxyClassLoader: defined LiveConnectProxy class. >>>
    <<< Here're the permissions you've got: >>>
    <<< java.security.Permissions@b614d0 (
    (java.net.SocketPermission 127.0.0.1 connect,accept,resolve)
    )I'm using the plugin.jar (replacing use of the old netscape.jar)
    to bridge communication between Java Applets and JavaScript.
    Each time the Applet calls back to the JavaScript side,
    the callback JavaScript function makes a call to parseInt() to
    convert one of the parameters passed from a string to an integer.
    Each time parseInt() is called, the message above appears
    in the Java Console.
    I traced down the source code for this message to a debug()
    statement inside the plugin.jar's class loader, but I'm not sure
    how to suppress it easily.
    Does anyone have any ideas I could try?
    Here's the code from the Java-side:
    synchronized( this )
         try
              final JSObject window = JSObject.getWindow( applet );
              if( window != null )
                   final String[] stringArgs = new String[3];
                   stringArgs[0] = labelName;
                   stringArgs[1] = labelDisplayName;
                   stringArgs[2] = labelValue;
                   log.debug(stringArgs[0]);
                   log.debug(stringArgs[1]);
                   log.debug(stringArgs[2]);
                   window.call("MyJavascriptCallback", stringArgs);
              else
                   log.error("Javascript window unavailable.");
         catch( final JSException e )
              // Note: Occasionally, getWindow() will throw an exception
              // without any meaningful reason.
              // ( http://www.raditha.com/blog/archives/000938.html )
              // Possible cause: This can send updates at a fraction of a
              // second. This may be causing issues within the Plugin.jar
              // used to handle the JavaScript callback.
              log.debug("JSException", e);
    }

    Here's what I've found out...
    The messages are coming from the MRJPlugin.jar provided by Firefox.
    Within the netscape.oji.ProxyClassLoaderFactory class,
    the following line...
    System.out.println("<<< " + message + " >>>");
    ...appears to be the cause and cannot be turned off by a configuration setting.
    The home URL for the MRJPlugin.jar is:
    http://www.mozilla.org/oji/MRJPlugin.html
    The last time this library had an update released was in 10/31/2000.
    However, this is the Mozilla source; not Firefox.
    Although changing the MRJPlugin.jar source to remove this line will appear
    to fix the problem, I'm not sure of the best way to distribute the updated
    MRJPlugin.jar without conflicting with Firefox's update process.
    Any thoughts?

  • Is there an easy way to append a new column of data to an existing xl file?

    I am modifying and existing program and the new needs are to have a compilation of averaging information to later be plotted with an xl graph. The VI will need to open the existing xl file, add the new column of data points without disturbing the existing columns of data, with a column header, and save the new file with the existing file name. The open and save are obviously not a problem, but I have never appended a new column, just rows in the past. The existing program is LV5.1, but i have a professional developement version of LV6i at my disposal if I need to convert it. Thank you in advance for any suggestions.
    Tim Fleeger
    Siemems Medical Systems

    TMF:
    INdeed there is. YOu want to use the "write characters to file" node. (If you're using numerical data, you might have to convert with one of the STRING conversion functions) YOu want to concatenate the string as follows: TAB/DATA/CARRIAGE RETURN. Also be sure to wire TRUE to the Append File terminal of the WRite Characters to File node.. Good luck!
    Eric P. Nichols
    P.O. Box 56235
    North Pole, AK 99705

  • Is there an easy way to remove audio track from .mp4

    Guys
    Wondered if anybody knows of a way to take a .mp4 file with a silent audio track exported and remove that audio track altogether without having to reconvert the video in AME- just deleting the (silent) audio track
    Have lots of files that need this and was looking for a way to do this without going back and reexporting  all the clips the hard way
    Any thoughts much appreciated-- (I have access to both Windows 7 and WIndows XP pro 64 bit)
    Thanks
    Tony

    Thanks Jim
    I figured that would work but for some reason the resulting files did not play correctly--Alternatively I used Mpegstreamclip -opened the video I wanted to erase audio track from--- clicked on "edit--delete audio track" then clicked "save as" and this finally accomplished what I was trying to do--Now have a copy of the .mp4 file wo audio
    Thanks for all your help--Hope this thread helps someone in the future
    Peace
    Tony

  • Is there an easy way to create a random character?

    I tried generating a random int with the Random class and casting it to a char, but when I try to print it (which is the whole thing I want), it prints it as a number. How do I print it as the character?
    Edited by: drummerp on Dec 1, 2009 3:05 AM

    Ok, I changed my program to only use the Ascii codes for the letters, so that it would do what I want. But the problem is that now it prints a number instead of the character...
    What I'm trying to do is create a random word generator program, just for fun. You have to understand, I'm pretty new to programming, I just did this to see if I could and to entertain myself because I was bored...
    Here's the SSCCE (tell me if this still isn't what your looking for in an SSCCE):
    public class WordMaker {
         public void go() {
              Timer t = new Timer(5000, new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        int len = r.nextInt(50) + 1;
                        for (int i = 1; i < len; i++) {
                             if (i == 1)
                                  System.out.print((char)r.nextInt(26) + 65);
                             else
                                  System.out.print((char)r.nextInt(26) + 97);
                        System.out.println();
              t.start();
              //Display a messagw box to prevent the
              //program from ending immediately
              JOptionPane.showMessageDialog(null, "Click OK to end the program");
              System.exit(0);
    }Edited by: drummerp on Dec 1, 2009 4:36 AM

  • Is there an easy way to download text messages from a LG Octane to a computer?

    Rather than forward each one.

    You can try BitPim (bitpim.org),  The Octane is a "feature" phone, a step up from basic, but not a full on smartphone ("proprietary OS", not Android, iOS, Windows, and app support is limited to BREW).
    BitPim may say the phone is not supported, but you may be able to get access to the text messages to download by using a similar model phone.

Maybe you are looking for

  • Need BADI or user exit to check info record on MM41/MM42.

    System:  SAP ECC 6.0 Retail Problem:  During article maintenance (MM41/MM42), we want to check certain fields on the info record (EINA) for only one valuation class. Steps already taken:  Checked the current BADi.  The current BADi, BADI_MATERIAL_CHE

  • XY Graph properitie​s

    I want to change plot's properities in XY graph. I used Property Node. I chosed Properities --> Plot --> Point Style, and it works, but it works only for "Plot 0" other plots have no change. How can I change properities for all plots? BTW Sorry about

  • Weblogic SSO with Negotiate Asserter to AD Windows2003

    Hi Im making the configuration of the SPNEGO negotiate asserter of Weblogic 11gR1 to enable SSO in Windows clients without the need of entering credentials. I went through the steps of the Securing Oracle WebLogic Server guide, http://download.oracle

  • Trouble with median function

    I need to use median function in fact table in my repository. In business model I have fact table with logical column(column where I used median function with name "MyCalculacion"). And I have Time dimension with column ("Year", "Quarter"(with value:

  • How to display two different hierarchical sequential lists in one o/p scree

    Hi Gurus, I have a requirement for displaying two hierarchical lists in one output screen. I have created my hierarchical sequential lists using function module : - 'REUSE_ALV_HIERSEQ_LIST_DISPLAY', but i dont know how to append my second hierarchica