rand.NextDouble(1234567891

and let me know if it works

Solved

Posted on 2012-08-21

Hello,

i have trouble using the rand.NextDouble()

for example i want to use

but i get this erro

but when i use the random generator for an integer like this

why is this ? can someone please help me

thank you

i have trouble using the rand.NextDouble()

for example i want to use

```
rand.NextDouble(12345678912345, 123456789123456);
```

but i get this erro

```
Error 1 No overload for method 'NextDouble' takes 2 arguments
```

but when i use the random generator for an integer like this

```
rand.Next(2345, 123456);
```

it works why is this ? can someone please help me

thank you

7 Comments

rand.NextDouble(1234567891

and let me know if it works

http://stackoverflow.com/q

using rand.Next(,); or something similar to it

```
Random rand = new Random();
const long upperBound = 1000000000000000;
long result = (long)(upperBound * rand.NextDouble());
```

That would return a result between 0 and 999999999999999, inclusive. If you want to start at 100000000000000, then we would have to modify the logic a bit.

The idea is always the same: NextDouble() returns a random number between 0 and 1, but with a huge precision (double precision, this is a 64 bits float number). All you have to do is just to manipulate this number to get what you want: multiply it by the range of numbers you want, and adds the initial number you want.

For example if you want a number between 3 and 10 (not included), do the following:

result = 3 + rand.NextDouble()*7;

where 7 is 10-3

If you want to include 10 then add 1 more (8 instead of 7).

Hope it helps.

```
private void button1_Click(object sender, EventArgs e)
{
long value = RandomNumber(15);
label1.Text = value.ToString();
}
private Random R = new Random();
private long RandomNumber(int length)
{
if (length >= 1 && length <= 18)
{
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= length; i++)
{
if (i == 1)
{
sb.Append(R.Next(1, 10).ToString()); // 1 to 9 inclusive
}
else
{
sb.Append(R.Next(0, 10).ToString()); // 0 to 9 inclusive
}
}
return Convert.ToInt64(sb.ToString());
}
else
{
throw new Exception("Invalid Number Length. Must be between 1 and 18.");
}
}
```

By clicking you are agreeing to Experts Exchange's Terms of Use.

Join the community of 500,000 technology professionals and ask your questions.

Connect with top rated Experts

**16** Experts available now in Live!