filling array with rand numbers

  • Thread starter Bill Cunningham
  • Start date
J

James Kuyper

Keith Thompson:
That doesn't do the same thing. If corrected, Bill's program
would set each element to a random integer from 0 to RAND_MAX.
Your suggestion would set each element to a value from 1 to n with
no repetitions.

*WHOOSH*

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.
 
M

Malcolm McLean

On Mon, 05 Aug 2013 13:51:42 -0400, James Kuyper

I don't believe Bill is a troll. I suspect he's a retired old
gentleman with nothing better to do with his time and an interest in
the topic and the challenge of programming. Whether he's medicated or
not is not for me to judge. Whether he learns or not is not my
responsibility nor do I feel obliged to reply to him or make him
learn. We all have our deficiencies and our strengths.

I also feel that anyone who feels he's a troll should ignore his posts
and simply behave like civil human beings and stop adding to the noise
in threads started by him. Those who troll the troll are trolls
themselves.

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top