473,395 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Random Double with a given Range

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
1 4016
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Nicholas Geraldi | last post by:
Im looking for a decent random number generator. Im looking to make a large number of random numbers (100 or so, if not more) in a short period of time (as fast as possible). the function i was...
70
by: Ben Pfaff | last post by:
One issue that comes up fairly often around here is the poor quality of the pseudo-random number generators supplied with many C implementations. As a result, we have to recommend things like...
2
by: Peter Williams | last post by:
Hi All, I need to port the following (small) C language function to Delphi: double Rand(void) { return rand()/(1.0 + (double)RAND_MAX); } NB -- elsewhere in the program randomize is called...
13
by: Jon Agiato | last post by:
Hello, I am sure this problem is easy to spot but I have been at this project all day and the frustration has finally overcome me. I am using this function in order to produce a standard normal...
7
by: BOOGIEMAN | last post by:
//Why this doesn't work : using System; using System.Threading; class RandomObjectDemo { public static void Main( ) { Thread.Sleep( 1 );
5
by: Peteroid | last post by:
I know how to use rand() to generate random POSITIVE-INTEGER numbers. But, I'd like to generate a random DOUBLE number in the range of 0.0 to 1.0 with resolution of a double (i.e., every possible...
3
by: JoelPJustice | last post by:
I am working through a VBA book by myself to help and try and improve my skills. However, the book does not give you solutions to certain problems. I have worked through this problem up until bullet...
28
by: Elfour | last post by:
In c++ what is the code to make teh program randomly select a number?
22
by: gagan.singh.arora | last post by:
Hi there. I want to generate random numbers with a given probability, say 80% even and 20% odd. Is it possible to implement such an algorithm in C?
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.