Menu

Generating A Vector of Random Numbers

2008-10-16
2012-09-26
  • Chris Hammond

    Chris Hammond - 2008-10-16

    I'm using DevC++ 4.9.9.2 on Windows XP. I want to generate a lot of random numbers all at once. I tried to do this by calling rand() repeatedly, but that doesn't work (I gather that it has something to do with the fact that the time hasn't changed much). I know that in Matlab, you can specify how many random numbers you wish to generate.

     
    • cpns

      cpns - 2008-10-17

      > I tried to do this by calling rand() repeatedly, but that doesn't work
      > (I gather that it has something to do with the fact that the time
      > hasn't changed much)

      No, it is because you were doing it wrong! rand() is not dependant in any way on time. It is common to seed the RNG with a value derived from time by passing a time related value to srand(), but you only need to do that once. My guess is that you are doing it before every call to rand() in the loop - which is just dumb - and not random! ;-)

      Clifford

       
    • Wayne Keen

      Wayne Keen - 2008-10-17

      I believe you can do that through GSL, the Gnu Scientific Library. There have been a number of discussions about using GSL in the pages of this forum.

      Wayne

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.