faster alternative to Math.random()?

hi,

i have profiled a mini-game i've written and found that calls to Math.random are taking up a good proportion of the time (5%). The source for Math.random() ispublicstaticdouble random(){

if (randomNumberGenerator ==null) initRNG();

return randomNumberGenerator.nextDouble();

}

which is exactly as expected.

I don't need any statistical guarantees about the randomness (just need to add some noise to some moving entities paths), so was wondering if there are any neat tricks to do this faster..

thanks,

asjf

[824 byte] By [asjfa] at [2007-9-29 6:15:38]
# 1
do you need a double?if not, you can use java.util.Random.nextInt(), which should be marginally faster.Another alternative is to pregenerate several 1000 random numbers, stick them in an array, and just cycle through the array.
Abusea at 2007-7-14 20:23:02 > top of Java-index,Other Topics,Java Game Development...
# 2

> Another alternative is to pregenerate several 1000 random numbers,

> stick them in an array, and just cycle through the array.

actually, might do that! (do need doubles half the time, but will convert the others to ints)

otherwise have found this which looks v. promising:

http://www.honeylocust.com/RngPack/

asjfa at 2007-7-14 20:23:02 > top of Java-index,Other Topics,Java Game Development...
# 3
1/20 isn't too much. It would be nice if you'd imagine what it could do with your program.
Lord_of_the_chaosa at 2007-7-14 20:23:02 > top of Java-index,Other Topics,Java Game Development...