"Daniel Dyer" <(E-Mail Removed)> wrote in message

news

(E-Mail Removed)...

> On Thu, 26 Jan 2006 17:45:29 -0000, Jeremy Watts <(E-Mail Removed)>

> wrote:

>

>> how would you produce a random decimal number in java, say 0.05663?

>

> http://java.sun.com/j2se/1.5.0/docs/...h.html#random()

>

> or

>

> http://java.sun.com/j2se/1.5.0/docs/...ml#nextDouble()

>

>> i can seem to produce random integers but not doubles

>

> How?
To the OP, if you're in some special environment where you can generate

random integers but not doubles (J2ME perhaps?), you can just divide your

integers to turn them into decimal values.

<pseudoCode>

Generate a random integer between zero and a million.

Divide that integer by a million to get a decimal value between 0 and 1.

</pseudoCode>

However, if you have access to the nextDouble() method mentioned above,

you should probably use it, as it may produce "better" (more random?)

results.

- Oliver