By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,894 Members | 2,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,894 IT Pros & Developers. It's quick & easy.

Random Double with a given Range

P: n/a
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[i]=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
Sep 29 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Martin Pöpping schrieb:
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
Sep 29 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.