Generate a number between 0(inclusive) to 1(inclusive)?

Hi all,I have read the API doc and discovered that the nextDouble() method of the Random class generates a number between 0(inclusive) to 1(exclusive). But I want 1 to be inclusive, so may I ask how this can be done?Thanks a lot.
[250 byte] By [HELLOOOOa] at [2007-10-2 22:12:31]
# 1
What other requirements do you have? Do you want every double in [0, 1] except the denorms represented with equal probability?
YAT_Archivista at 2007-7-14 1:29:26 > top of Java-index,Java Essentials,New To Java...
# 2

Well, if you read the documentation you'll see that the probability of returning any particular float number is 1/2 to the power 53. So in your proposed variant, that would be the probability of returning 1. Basically your proposed variant is indistinguishable from the existing method; you would have to select 2 to the power 52 random numbers before you might expect to see 1 appear. It would take longer than your lifetime to do that.

In other words, you're wasting your time with this question.

DrClapa at 2007-7-14 1:29:26 > top of Java-index,Java Essentials,New To Java...
# 3
Math.abs(1-rand.nextDouble()*2)
Michael_Dunna at 2007-7-14 1:29:26 > top of Java-index,Java Essentials,New To Java...
# 4
Math.random() also generate number from 0 to 1 inclusive.but the chance to get 0 or 1, are very low.
eh2001a at 2007-7-14 1:29:26 > top of Java-index,Java Essentials,New To Java...
# 5
> Math.random() also generate number from> 0 to 1 inclusive.> > but the chance to get 0 or 1, are very low.No!Math.random() also generates numbers less than 1 and each number has the exact same probability of being generated.
floundera at 2007-7-14 1:29:26 > top of Java-index,Java Essentials,New To Java...
# 6

> > Math.random()

also generate number

> from

> > 0 to 1 inclusive.

> >

> > but the chance to get 0 or 1, are very low.

>

> No!

>

> Math.random() also generates numbers less than 1 and

> each number has the exact same probability of being

> generated.

Yes, and that probability is so miniscule that the chances of getting 0 or 1 is very low. The chances of getting <insert any specific number> is very low.

kablaira at 2007-7-14 1:29:26 > top of Java-index,Java Essentials,New To Java...
# 7

> > > Math.random()

also generate number

> > from

> > > 0 to 1 inclusive.

> > >

> > > but the chance to get 0 or 1, are very low.

> >

> > No!

> >

> > Math.random() also generates numbers less than 1

> and

> > each number has the exact same probability of

> being

> > generated.

>

> Yes, and that probability is so miniscule that the

> chances of getting 0 or 1 is very low. The chances

> of getting <insert any specific number> is very low.

Point taken! I was assuming they meant relative to other numbers.

floundera at 2007-7-14 1:29:26 > top of Java-index,Java Essentials,New To Java...