Randomising order of elements in vectors

hi
i have a vector containing vectors containing Doubles (nightmare, i know!). Just wondering if there's an easy way of randomising the order or the elements in the main vector.
thanks,
al

This can be improved.
public class ARandouPermutation{
public static void main(String[] args) throws Exception{
java.util.Vector vec = new java.util.Vector();
for(int i=0;i<64;i++){// 64 is an example
    vec.add(new Double(i*1.0));
Object[] tmp0 = vec.toArray();
int originalSize = vec.size();// obtaining the original size of the Vector
vec.clear();  // setting to size zero
Object[] tmp1 = new Object[originalSize];
int[] indexarr = randPermute(originalSize);// this method is defined below
for(int j=0;j<indexarr.length;j++){
    tmp1[j] = tmp0[indexarr[j]];
tmp0=null;
arr=null;
for(int j=0;j<originalSize;j++){// this can be replaced by java.util.Arrays.asList(Object[])
  vec.add(tmp1[j]);
  System.out.println(((Double)vec.get(j)).toString());//test output
public static int[] randPermute(int L){// length L of the array returned is passed as an argument
   if(L<0) throw new IllegalArgumentException();
   int[] arr = new int[L];
   java.util.Random rand = new java.util.Random();
   for(int j=0;j<L;j++) arr[j]=j;
   int tmp, index=0;
Label:   while(index<L){
       tmp = rand.nextInt(L);
       for(int j=0;j<index;j++) {
            if(tmp==arr[j]) continue Label;
        arr[index]=tmp;
        index++;
   return arr;
}

Similar Messages

  • Travel Expenses settlements against Service Order/WBS Element/Project Ord

    Hi Experts,
    I have one req. in Travel Expenses, i.e. need to settle travel expneses against Service Order/WBS Element/Project Order.
    Can you guide me how to do this req.
    Thanks & Regards
    Rajesh

    Hye mate,
    This is possible for sure what you need to do is to go at travel request . In travel Request there is an option of Enhanced Travel cost/ Alternative master cost center. if you click on it . you would find an option of cost assignmnet click on it
    there you would have option , like an excel sheet like fields of  the cost centre, wbs element, profit center, order number what eve is requred and save it.
    now the cot of trip would go that particulat cost center or der numbe or WBS rather then the cost center assigned at master data in ifototype 0027.
    Regards
    Waqas Anwar

  • How can i change the order of  elements in a JList ?

    Hi,
    i would like to know if it is possible to change the order of elements in a JList ? Maybe i could use drag and drop to do this ?
    Thanks for answering.

    The simplest way is probably to implement ur own listmodel and then supply the listitems in the order u want. Example:
    class MyListModel
              extends AbstractListModel
              implements ContactListListener {
    public int getSize() {
    return listitemcount;
    public Object getElementAt(int index) {
    //here u return the item for the index at the list
    //if u for example have an array of strings
    //which u wanna have listed in reversed order (reversed to
    //the order in the array, u could do
         return myarray[getSize()-index];
    }

  • How to export an album and keep images in the same order in elements 11 mac

    I made an album of my trip to Australia (lots of pictures) and changed the order of the images (not the same as shooting order) and when I export the images in the album to a folder or memorystick, the images are copied to that place but I lost the album order of the images.
    How can I prevent that, without having to renumber al 500 images separatly?
    Gr Jos

    Thanks for the tip, Michel
    It worked like a charm…
    cheers Jos
    Op 28 okt. 2013, om 18:49 heeft MichelBParis <[email protected]> het volgende geschreven:
    Re: How to export an album and keep images in the same order in elements 11 mac
    created by MichelBParis in Photoshop Elements - View the full discussion
    JosU a écrit:
    I made an album of my trip to Australia (lots of pictures) and changed the order of the images (not the same as shooting order) and when I export the images in the album to a folder or memorystick, the images are copied to that place but I lost the album order of the images.
    How can I prevent that, without having to renumber al 500 images separatly?
    Gr Jos
    The order in album is only kept in the organizer database, so the only way not to lose that order is to rename files.
    If you are using the 'export' function, select your album in custom order, select all photos and in the dialog, choose to rename with a common base name.
    Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/5794538#5794538
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/5794538#5794538
    To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/5794538#5794538. In the Actions box on the right, click the Stop Email Notifications link.
    Start a new discussion in Photoshop Elements at Adobe Community
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Reverse the order of elements in an array

    how would i go about Reverse the order of elements in an array??

    I link to the javadocs can't be too bad. [url
    http://java.sun.com/j2se/1.5.0/docs/api/java/util/Coll
    >
    ections.html#reverse(java.util.List)]Collections.rever
    se(List)Of course I fortell the next question, but I wantan
    Array not a List? So I provide the next link:[url
    http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arr
    ys.html#asList(T...)]Arrays.asList(T...)Yeah but then you have to worry about the next
    question which is more of a statement: "I can't use
    Arrays".
    Then I would as them: How would you do it in real life? Of course they could think a real world way of doing it. In that case, I'll give them an real life example.
    Assumed List
    1 2 3 4 5 6 7 8 9 10 11 12 13
    Switch the first and the last elements
    13 2 3 4 5 6 7 8 9 10 11 12 1
    Then the second and second to the last
    13 12 3 4 5 6 7 8 9 10 11 2 1
    And repeat until your half way.
    13 12 10 4 5 6 7 8 9 3 2 1
    13 12 10 9 5 6 7 8 4 3 2 1
    13 12 10 9 8 6 7 5 4 3 2 1
    13 12 10 9 8 7 6 5 4 3 2 1
    Done.

  • Will the order of elements stored in pl.sql table retains

    Hello Friends,
    I am having a record type and the for each element of record , i am having corresponding pl.sql table type .
    If i am storing the values into the records from a query and also the individual elements in the pl.sql table type will the order of data is stored as it is . ..
    example...
    in a record type the data is stored as ( name1 , age1 , salary1) , (name2, age2, salary2)
    if i store in corresponding pl sql table type name1 , name2
    age1, age2
    salary1, salary2
    can i relate the index of record type with that of pl/sql table type ..
    pls advice
    thanks/kumar

    Kumar,
    Yes, the order of elements will be the same.
    Any specific reason why you would want to create a collection for each individual attribute of the record ?
    You can as well declare another variable of the same record and initialize it.
    A few other suggestions for your code :
    1) The 2nd FOR loop can be modified to accommodate the query of the first cursor there-by eliminating one extra iteration.
    SELECT MINC.FAMID,
                         MINC.MEMBNO,
                         MEMB.AGE,
                         SALARYX,
                         SALARYBX,
                         NONFARMX,
                         NONFRMBX,
                         FARMINCX,
                         FRMINCBX,
                         CU_CODE
                    FROM MINC, MEMB, FMLY
                   WHERE MINC.FAMID = MEMB.FAMID
                     AND MINC.MEMBNO = MEMB.MEMBNO
                     AND MINC.FAMID = FMLY.FAMID
                     AND MEMB.FAMID = FMLY.FAMID
                   ORDER BY MINC.FAMID2) The collections can be alternately initialized as follows :
       v_member_rec(v_member_rec.last).FAMID := j.FAMID;
       max_earnings_tab(max_earnings_tab.last) := v_max_earnings;The tried the below example for confirmation ...
    declare
    type emp_rec is record
    (name emp.ename%TYPE,
      dept emp.edept%TYPE,
      sal  emp.esal%TYPE
    TYPE emp_rec_tab is table of emp_rec;
    ert emp_rec_tab := emp_rec_tab();
    TYPE ename_tab is table of varchar2(20);
    ent  ename_tab := ename_tab();
    TYPE edept_tab is table of number;
    edt  edept_tab := edept_tab();
    begin
    for i in (select * from emp)
    loop
         ert.extend;
         ent.extend;
         edt.extend;
         ert(ert.last).name := i.ename;
         ert(ert.last).dept := i.edept;
         ert(ert.last).sal := i.esal;
         ent(ent.last) := i.ename;
         edt(edt.last) := i.edept;
    end loop;
    for i in 1..ert.count
    loop
         dbms_output.put_line(ert(i).name||','||ent(i));
         dbms_output.put_line(ert(i).dept||','||edt(i));
         dbms_output.put_line('');
    end loop;
    end;

  • Have ordered Photoshop Elements 12 and Premiere Elements 12 (for MAC, EN version). Order went through but finally order was cancelled as Adobe Store was unable to approve. Subsequently order was cancelled. did anybody experience the same issue and how to

    Have ordered Photoshop Elements 12 and Premiere Elements 12 (for MAC, EN version). Order went through but finally order was cancelled as Adobe Store was unable to approve. Subsequently order was cancelled. did anybody experience the same issue and how to proceed.

    Hi there
    Please check with your credit card issuer to see why payment is not being approved.  When this is resolved you should be able to place a new order.
    Thanks
    Bev

  • I uploaded the upgrade to Photoshop Elements 12 today.  I got a "dispatching error" for Photoshop Elements, but was able to download Premier elements!  I did not order Premier Elements, so I'm confused (unless this was a package that I did not know about)

    I uploaded the upgrade to Photoshop Elements 12 today.  I got a "dispatching error" for Photoshop Elements, but was able to download Premier elements!  I did not order Premier Elements, so I'm confused (unless this was a package that I did not know about).  I really want the Photoshop Elements upgrade - not Premier Elements.  I do hope I did not pay for both - I only want one.  Help!

    Maryrhire910 I am sorry that you are facing difficulty downloading and installing Photoshop Elements 12.  Are you downloading the installation files from Download Photoshop Elements products | 13, 12, 11, 10?  If so what specific error are you receiving?

  • Will Vector keep the order of elements?

    I would like to quickly add lines of a file into a vector to get the size. I then create an array using that declaring that number of elements, then read each vector element into the array. I thought I read somewhere that a Vector may swap the order of the elements?

    I thought I read
    somewhere that a Vector may swap the order of the
    elements?Well, if you did read that somewhere it might be true. If you write some serious code you cannot buy what people just say. You have to look into it for yourself and ESTABLISH what goes with your chosen data-structure.
    PS. My advice to everybody is to look into this stuff and convince yourself you're doing the right thing.

  • Sale order - Wbs element Report

    Hi
    Is there any report for sale order wise wbs element report.
    In my sale order i will give wbs element and now i want to check "for one sale order , what are the wbs elements"

    You can check the WBS for a sales order from the table view of VBAP.
    The WBS field is PS_PSP_PNR.
    Goto SE16 and give VBAP.
    Enter your sales order number and execute. Look for your WBS elements in foeld PS_PSP_PNR for the different line items.
    You can also create a quick SAP query on this.

  • Get hierarchy of internal order / WBS element

    dear all ABAP guru,
    i have a problem to view hierarchy of internal table or WBS element,
    anyone know function module or table to view hierarchy of internal order / WBS
    many thx,

    You can also use BAPI_PROJECT_MAINTAIN for Project/WBS for internal order  following function module can help BAPI_INTERNALORDER_GETDETAIL
    BAPI_INTERNALORDER_GETLIST.
    Nabheet

  • Creation of sales order/wbs element

    Hi SAP gurus,
    While creating a sales order after entering the WBS element, I am getting an error
    Profit Ctr not consistent between Plant and Material/WBS for line item 0010
    can somebody throw light and help to solve.
    regards
    Pranav shah

    Hi ,
    check the plant for your material and in your project. both should be same.
    cheers,
    sumith

  • Settlement of order -WBS Element

    Dear Experts,
    Can any one tell me what is meant by WBS element and in what scenario,PM orders settlement rule created with category as WBS.If possible tell me with any practical example.
    regards
    KRISHNAN

    Dear,
    Dear,
    Budget: Amount of resources allocated under a particular head in a financial year.
    Budget Control: Having/ creating a control on the resources allocated in a financial year.
    Original Budget: The initial budget that you have allocated to a WBS element.
    Supplement of Budget: One time/ discrete increment in the original budget.
    Return of Budget: Taking out the unutilized portion of the budget.
    Transfer of Budget: Transferring the budget among two or more expense heads.
    Project Definition: A framework for a business undertaking with a fixed goal to achieve with given resources.
    The project definition contains dates and organizational information that are binding for the entire project.
    WBS Element: Individual structural element in a work breakdown structure (WBS) representing the hierarchical organization of an R/3 project. Describes either a concrete task or a partial one that can be further subdivided.
    Proposed Business Process
    Assume there are seven expense heads in maintenance department. There may be addition of expense head in near future.
    Based on the maintenance heads, maintenance department will create a project in project system. This project will be used for ‘statistical purpose’ only & will not have any financial implication.
    Upon creation of a project, WBS elements will be created as per the expense heads. So for each expense head, there will be one top level WBS element. Again these WBS elements will be divided in twelve WBS elements. These twelve WBS elements represent twelve calendar months.
    Budget will be allocated to each WBS element & the WBS element will be released from the project.
    Maintenance department will create maintenance orders as per their work requirements. These orders will be settled to cost centre, which is maintained in the settlement rule. Also WBS element will have to be mentioned in each order so that the budget control can take place. So as to capture cost from each maintenance order, the WBS element field will be made ‘mandatory field’ in maintenance order.
    So when a maintenance order is released, system will do a budget check against the WBS element mentioned. If the budget check status is OK, order is released or else it will stopped from release. If the order is stopped from release, maintenance department will have to supplement the budget. Upon supplementing, the order is released again & the maintenance cost such as, labour, material costs can be booked on the order. Again the order cost is settled to cost centre & at the same time, budget is consumed from the respective WBS element.
    Every year, maintenance department will copy the previous year’s project so as to save time & efforts to create project & WBS elements. And the maintenance department will assign the budget allocated to each WBS element in a financial year.
    It is also possible to return the unutilised budget or, transfer of budget from one WBS element to another.
    Create a project CJ20N
    Create WBS element CJ20N
    Assign Budget to WBS elementsKO22
    Display assigned Budget KO23
    Supplement Budget KO24
    Display Supplement budget KO25
    Return Budget KO26
    Display Return budget KO27
    Transfer of budget CJ34
    Hope u wull get ur answer
    Regards
    Rakesh

  • Service order - WBS element

    In Service Order,
    we are doing a settlement to WBS element.
    I want to see a report through WBS element the costs, settled through Service Orders.
    Is there any Standard report.
    Please suggest.
    Raja

    Hi,
          If settlement is done to WBS then the cost would reflect under Actual Costs of WBS :
    Check if u can find in report :-S_ALR_87100188 or S_ALR_87013531 ..
    regards
    pushpa

  • Sale Order # - MRP element missing in MD04

    Hi,
    I created an SO with a material, for which planning was not done in MRP view. Later I changed the schedule line category from CN to CP in VA02. Then MRP run is carried out for that particular plant (1001) . IN MD04, i could able to get the details of that particular SO except the MRP element Data . SO # is missing.
    Regards,

    Hi,
    Sale order no. is missing., say 3820. All the details of this SO is furnished properly in line, but the SO # column is blank. And to give you an extra detail, all other SO # for this particular material is displaying in its corresponding column.
        In my observation, if some changes (like changing the schedule line category, order reason), doing such changes effects in displaying the SO # in MD04.
        Pl do help me to display it and could anyone pl tell me what will be the reason for this blank column.
    Regards,

Maybe you are looking for

  • What is the best (used) model of Xserve?

    Hello Xserve folk. I plan on purchasing a used Xserve soon somewhere like on eBay and using it in a data center to host some websites. (I now use an old Sun Raq 550) My question to you all: what would be the best model/configuration? Naturally a bran

  • Error extracting SAP NetWeaver 7.0 (2004s) - ABAP Trial Version

    Hi Friends, I am getting the following errors when extracting the part1 with winrar, ive tried for extracting it thrice but didn't succeed, pl help.... ! F:\SAPNW7.0ABAPTrialSP12.part1.tgz: CRC failed in SAPNW7.0ABAPTrialSP12\image\load\load_datasave

  • How do i get itunes to sync without losing my music

    i have synced my phone twice and both times have lost my music.  i cannot get my music to transfer to my computer.  the latest time one album synced.  the other 100 or so song disappeared

  • Photo Montage Has (white edge) On Some Frames

    I use Memories on TV to make picture montages. Some times when I make a opening picture in Photoshop like a title or some thing. I get a white edge around two side of the first image of the slide show. I found a action one time that was to remove tha

  • How To Reinstall The Mac App Store?

    When someone was on my computer they used App Cleaner to delete it entirely. I'm not sure if its a joke or whatever. How do I redownload/install it? I'm using a early 2011 MPB running Mac OS X Lion.