filling array with rand numbers

Discussion in 'C Programming' started by Bill Cunningham, Aug 4, 2013.

  1. Bill Cunningham

    James Kuyper Guest

    Keith Thompson:

    Let's go back to Bill's original post (emphasis mine):

    If you just move the rand() inside the loop, there's no guarantee that all
    of the numbers will actually be different.[/QUOTE]

    True - but out of what range does he want them to be randomly selected?
    If he wants them to range from 0 to RAND_MAX, calls to rand() followed
    by rejection of duplicates is probably the best approach, at least if
    the number of values needed is much smaller than RAND_MAX.
    James Kuyper, Aug 7, 2013
    1. Advertisements

  2. He's on topic and he's not rude or aggressive, so there aren't any grounds for
    complaint. If it's a joke then it's a clever and good one.

    I don't normally find there's much I can usefully say in response to Bill,
    but I usually read him. Usually there's an answer to the question already posted, so I don't pay any more attention to the thread. But I neither
    encourage nor discourage other people from responding.
    Malcolm McLean, Aug 7, 2013
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.