randomly remove elements

This is a discussion on randomly remove elements within the C++ Programming forums, part of the General Programming Boards category; It seems more difficult than i thought... Ok,another question..Suppose that i have a set( vector) with n elements. How can ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    58

    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 C++ satisfy a criterion. I don't need one. Just randomly remove some elements.

    Thanx

  2. #2
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    a vector? Do a random_shuffle and then resize the vector to half its size.
    There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    Oh, and I think you double posted Joan :}
    I'm just trying to be a better person - My Name Is Earl

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    58
    Yes, swgh..i didn't do it on purpose..

    sorry

  5. #5
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    I meant it light-heartedly, no need to apoligise, it is a mistake we all make once, somtimes this board is rather slow at processing a message
    I'm just trying to be a better person - My Name Is Earl

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    58
    Yes, exactly..i think that happend..
    Anyway, have u looked at my previous thread??

    Have u any idea?? anything would be helpful..if you don't understand sth from my description ask me.. :-)

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Replies here -> randomly remove elements
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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: 2
    Last Post: 12-06-2006, 11:22 AM
  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, 03:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21