You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Bogdan Jovanovski <bo...@mail.ccc-casino.com> on 2001/05/03 15:27:55 UTC
Problem with generating random numbers...
The follwing piece of code in one of our actions always produces the same
result, the same number. When we restart turbine, the result is different
but it remains the same regardless of how many times we activated the
action.
val = (int)(Math.random()*scale)
We also try this with Random() but the result is the same.
Any sugestions ?!!
Bogdan Jovanovski.
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org
Re: Problem with generating random numbers...
Posted by Jon Stevens <jo...@latchkey.com>.
on 5/3/01 6:27 AM, "Bogdan Jovanovski" <bo...@mail.ccc-casino.com> wrote:
> The follwing piece of code in one of our actions always produces the same
> result, the same number. When we restart turbine, the result is different
> but it remains the same regardless of how many times we activated the
> action.
>
> val = (int)(Math.random()*scale)
>
> We also try this with Random() but the result is the same.
>
> Any sugestions ?!!
>
> Bogdan Jovanovski.
You need to seed() the RNG.
-jon
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org
Re: Problem with generating random numbers...
Posted by Bogdan Jovanovski <bo...@mail.ccc-casino.com>.
As I said, we try that also.
B.
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org
RE: Problem with generating random numbers...
Posted by Gareth Coltman <ga...@majorband.co.uk>.
> The follwing piece of code in one of our actions always produces the same
> result, the same number. When we restart turbine, the result is different
> but it remains the same regardless of how many times we activated the
> action.
>
> val = (int)(Math.random()*scale)
>
> We also try this with Random() but the result is the same.
Try this:
import java.util.*;
Random rn = new Random();
int r = rn.nextInt()*scale; // 32-bit random number
The default constructor uses the current system time as a seed.
Gareth Coltman
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org