I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Programming » C/C++ »

generate 1000000 random numbers

mqueene7\′s Photo
31 Oct 07, 9:29PM
(1 reply)
generate 1000000 random numbers
I'm not sure how I should write this in C++ in order to generate 1000000 numbers because my professor said that rand() will not work. Does anyone know how to do this?

Thanks!
john\′s Photo
1 Nov 07, 9:43AM
There are two problem with rand():
  • first is that it isn't a particularly good uniform random generator. You can see this if you generate a large set of numbers and produce a histogram. You should find you have a near straight line, with numbers in all ranges occurring equally.
  • second the repeat period of the rand() isn't as height as some other generators. In otherwords if you try to produce a sufficiently long sequence of random numbers, you eventually reach a point when the sequence is identical to something produced earlier.

There are a couple of alternatives, some of which are on CodeCogs, have a look at this category: http://www.codecogs.com/pages/catgen.php?category=stats/random
Currently you need to be logged in to leave a message.