Thread: randomly remove elements

  1. #1
    Registered User
    Join Date
    Nov 2006

    randomly remove elements

    It seems more difficult than i thought...

    Ok,another question..Suppose that i have a set( vector) with n elements. How can i remove randomly let's say half of them??

    All the remove algorithms of the C++ satisfy a criterion. I don't need one. Just randomly remove some elements.


  2. #2
    Registered User
    Join Date
    May 2006
    I would either generate a random number between 0 and size() - 1 and do this for half of the elements or simply call random_shuffle() and delete size() / 2 elements of the vector. I would probably opt for the latter option.

    Edit: Oh, didn't see the other thread. Oh well, a mod can move my post to the other thread ?

  3. #3
    Registered User
    Join Date
    Nov 2006
    Ok..thanx a lot.

    Yes, by mistake i double posted

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Randomly rearranging the elements in a vector
    By Signifier in forum C++ Programming
    Replies: 11
    Last Post: 08-01-2007, 12:21 PM
  2. how to remove even elements from list
    By lastrial in forum C Programming
    Replies: 3
    Last Post: 05-17-2007, 10:59 PM
  3. randomly remove elements
    By joan in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2006, 01:46 PM
  4. Remove elements from array
    By Xentor in forum C++ Programming
    Replies: 8
    Last Post: 09-24-2006, 07:47 PM
  5. Replies: 5
    Last Post: 03-06-2006, 04:02 PM