Random Double with a given Range

G

Guest

Hello,

I´ve to implement an array which sum always have to 1.
In the API Documentation I´ve found Random.NextDouble(),
but it always returns a value x with 0.0 <= x < 1.0.

Is there a range to specify the random value a bit more?

I want to do it like this:

double[] myArray = new Array();

Random randomClass = new Random();

double random=0.0, currentValue=0.0, restValue=1.0;

for(int i = 0; i < myArray.Length; i++)
{
random=randomClass.NextDouble(0.0, restValue);
restValue -= random;
myArray=restValue;
}

But this would only work if I would have a method like
NextDouble(double startValue, double endValue).

Do you have any ideas how to solve me problem?


Regards,

Martin
 
G

Guest

Martin said:
I´ve to implement an array which sum always have to 1.
In the API Documentation I´ve found Random.NextDouble(),
but it always returns a value x with 0.0 <= x < 1.0.

Is there a range to specify the random value a bit more?

I solved my problem in a workaround.


Regards,

Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top