Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 32,527 of 33,346    |
|    =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All    |
|    Re: nrand() from Accelerated C++    |
|    05 Sep 12 11:19:35    |
      From: daniel.kruegler@googlemail.com              Am 05.09.2012 13:21, schrieb alessandro.suglia@googlemail.com:       > I'm reading in these days that chapter of the book, and I've found       > this example quite astonishgly and also quite difficult to       > understand simply because trying to execute your program I'll always       > receive a "random value" that is absolutely constant.       >       > I don't know why exactly, maybe it's a problem of my computer, but       > I've noticed that removing the division operator and substituting       > that one with the remainder operator, the result starting to be       > correct.       >       > So my question is, there are some errors in my book or it's simply a       > distraction error??              You haven't shown us the complete code, so my suspicion is that you       haven't called the function srand with a different value before       invoking the rand() function. The C standard says:              "If rand is called before any calls to srand have been made, the same       sequence shall be generated as when srand is first called with a seed       value of 1"              This means that you will get the same value for rand for the first       call.              But you should clearly observe that a series of calls of rand() within       the same program should produce a equally-distributed series of values       in the range [0, RAND_MAX).              HTH & Greetings from Bremen,              Daniel Krügler                     --        [ See http://www.gotw.ca/resources/clcm.htm for info about ]        [ comp.lang.c++.moderated. First time posters: Do this! ]              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca