std.random

Thomas Kuehne thomas-dloop at kuehne.cn
Tue Apr 11 11:35:38 PDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Charles schrieb am 2006-04-11:
> Charles wrote:
>> How do i get a number in the range -0.5 to 0.5 ?

const float RAND_MAX = uint.max;
float sum = 0.0;
for(size_t i = 1; i < 101; i++){
    float x = (rand() / RAND_MAX) - 0.5;
    sum += x;
    writefln("round:%s\t%s\t(%s)", i, x, sum / i);
}

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFEPAMv3w+/yD4P9tIRAvPEAJ42zaytStz2jn5BhwkB3YAM3D4B0ACgiDDk
8wfG8fdPa8ijUaDOVbdHW3g=
=xxyV
-----END PGP SIGNATURE-----



More information about the Digitalmars-d-learn mailing list