
4 Sep
2004
4 Sep
'04
7:38 a.m.
"Carlo Wood" <carlo@alinoe.com> wrote in message news:20040904030317.GA23364@alinoe.com... | On Fri, Sep 03, 2004 at 08:37:20PM -0600, Jonathan Turkanis wrote: | > > 2. tutorial docs: | > > | > > The first code example: | > > s[z] = (char) (rand() * 256 / RAND_MAX); | > > I think this causes overflows way too often. | > > s[z] = (char) (rand() % 256); | > > is more likely intended even if it | > > adds small bias. | | Please no, this is in every FAQ on the use of rand(). | The lower bits of rand() are not very random and | using (rand() % 256) would be a classical case of | misuse of that function. btw, there is no requirement in the standarf that rand() must be a stupid algorithms with this behavior. br Thorsten