|
Boost : |
From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2004-09-04 02:38:49
"Carlo Wood" <carlo_at_[hidden]> wrote in message news:20040904030317.GA23364_at_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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk