std.random

Charles noone at nowhere.com
Tue Apr 11 08:35:30 PDT 2006


Charles wrote:
> How do i get a number in the range -0.5 to 0.5 ?

To Clarify:

How do i get a random real in the range -0.5 to 0.5 using std.random ?

--

Even using the traditional C method , using std.c.stdlib, using int.max 
for RAND_MAX scince its not defined is not working ->

const int RAND_MAX = int.max;
float x = (rand() / (RAND_MAX + 1.0)) - 0.5;

This always yeilds numbers of ( -0.4999XX , where XX is from 80 99 ).

This code works as expected with DMC.

--

I have a workaround for now using the undocumented std.c.stdlib 
random(X) function with

return (random(50000) / 50000.0 ) - 0.5;

but would like to use D's std.random .

Charlie



More information about the Digitalmars-d-learn mailing list