Hi all,

Can someone please explain to me how can I generate a random (double) number from 0 to 1,including1?

I used this, but it excludes 1:

double RandomValue;

RandomValue = Math.random();

Thanks!

Printable View

- 11-29-2008, 05:03 PMoridovGenerating a random number
Hi all,

Can someone please explain to me how can I generate a random (double) number from 0 to 1,**including**1?

I used this, but it excludes 1:

double RandomValue;

RandomValue = Math.random();

Thanks! - 11-29-2008, 05:38 PMCJSLMANTry this...
Try this... Random class:

Random (Java Platform SE 6)

and specailly this method:

Random.nextInt(int n) (Java Platform SE 6))

Luck,

CJSL - 11-29-2008, 06:12 PMCJSLMANJust got another idea...
You can also take a certain level and turn into a 1. For example:

Code:`if (n == 0.99)`

{

n=1;

}

Code:`if (n > 0.95)`

{

n=1;

}

CJSL