random subset made by random selection of different elements from a given set

Discussion in 'C' started by elshadai, Mar 14, 2010.

  1. elshadai

    elshadai New Member

    Joined:
    Mar 14, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hey all,

    My name is Elshadai,

    I am just a beginner in C/C++. I want to write a code in C/C++ the can select randomly a subset of integers both different from a given set. To be more concrete I have the following situation:

    A=[1,2,3,4,5,6,7,8,9,10],


    I want to make a subset of 4 elements from A whose element are chosen from A randomly and those element must be different from each other. I need a sets like :

    B=[1,7,4,9] or C=[2,10,7,1] or D=[10,3,5,6] ....

    Is there any one can help me?

    Thank you so much
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Pick 4 random numbers. Check if any are equal. If they are, change one. Repeat until you have no more duplicates.
     
  3. elshadai

    elshadai New Member

    Joined:
    Mar 14, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Thank you for you idea,
    the problem is how to do what u say in c/c++?
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Do you know how to pick one random number?
     
  5. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice