can anyone tell what did i wrong on this random number? http://pastebin.com/M3J9u5sR

    srand( (unsigned int) time(0));


        for (int index = 0; index < size1; index++)
        {
            read[index] = (rand() % 30) + 1; // This will create 200 random number.
        }

    output is

    1-2-5-5-6-7-8-8-8-9
    9-10-13-13-15-16-18-18-19-20
    21-23-24-24-24-25-28-28-28-29

And what IS your problem. Most rand() functions are at best "pseudo-random" - ie, not so much. This is a good tutorial on the subject: http://www.phy.ornl.gov/csep/CSEP/RN/RN.html

From the site: page 2

 Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin. -- John von Neumann (1951) 

Anyone who has not seen the above quotation in at least 100 places is probably not very old. -- D. V. Pryor (1993) 

Myself, I like lagged-fibonacci sequences, salted with some really random variables such as the decay of some radioactive isotopes, the temperature at various locations on the earth, the current density of the solar wind impacting the earth, etc. FWIW, my wife is a particle physicist and uses Monte Carlo routines to model elemenatary physics. Really random number generators are essential in that work.

Did you sort the list after it was generated?

If you generated 200 random numbers in the range of 1-30, you should expect about 6 or 7 of each value to occur. Even in your set or 30 values, you will get duplicates.

Hi, "chubbyy.putto."

(Perhaps you could include at least your first name in your Profile, so we can address you with a proper name instead of your forum handle.)

Did you ever get your program working like you wanted?
Was your assignment to write the program, or did you just need the random numbers regardless of how you got them?

You might want to check out the Mersenne Twister algorithm; as far as I know, it is presently the best pseudo-random number generator available. It has an extremely long period (i.e. - generates MANY numbers before it starts to repeat.)

A web search turns up a lot of information about this algorithm, including source code in several languages; in fact, a search of the Daniweb forums turns up several discussions too. For example: http://www.daniweb.com/software-development/cpp/threads/311641/random-number-generator

There is also a web service that provides true random numbers: http://www.random.org/

From their home page: "The randomness comes from atmospheric noise . . ."
Apparently, they have a few radio receivers, which they use to sample atmospheric noise and generate random numbers. Depending upon your needs, you can specify the types of random numbers you need, and this free web service will generate them for you.

Hope this helps.

commented: Like their use of atmospheric "noise" to seed the generator! :-) +12
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.