How is Math.Random emulated? and how good is it?

169 views
Skip to first unread message

darkflame

unread,
Jan 11, 2012, 4:02:27 AM1/11/12
to Google Web Toolkit
I have been playing about drawing fractals in GWT using canvas and the
¨ chaos game¨ method.

However when picking large amounts of random numbers I seem to be
getting a bias. That is, the randomness doesn't seem evenly
distributed.
I have read many sources online that say that Javas normal
Math.Random() is flawed for this stuff, and some alternatives are
offered. However as GWTś Math.Random is merely an emulation, I
wondered if it suffered the same flaws or not.
Does anyone use alternative methods?

This is all rather new too me, so if anyone has any pointers it would
be helpfull.

Kevin Jordan

unread,
Jan 11, 2012, 8:19:33 AM1/11/12
to Google Web Toolkit
All GWT's emulation does is natively call the javascript
Math.random().

Chi Hoang

unread,
Jan 11, 2012, 9:21:13 AM1/11/12
to Google Web Toolkit
java.lang.Math.random() calls the native javascript Math.random().

However, java.util.Random implements the random number algorithm
specified in the spec for that class - you can try using that if
java.lang.Math.random() is not random enough

Jim Douglas

unread,
Jan 11, 2012, 11:53:19 AM1/11/12
to Google Web Toolkit

Kolban

unread,
Jan 11, 2012, 9:07:01 PM1/11/12
to google-we...@googlegroups.com
I stumbled across this today ...

http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/Random.html

It appears that there is also a Random class as part of the standard GWT client environment.  Is this the same as "Math.Random()?"

Neil

Trevor Skaife

unread,
Jan 12, 2012, 4:49:21 PM1/12/12
to Google Web Toolkit

darkflame

unread,
Jan 14, 2012, 7:10:21 PM1/14/12
to Google Web Toolkit
Thanks, I'll try that other one and see if it helps.

My Application/Doddle is here:
http://www.darkflame.co.uk//Modoodler/Modoodler.html
If anyone is interested. Hitting Run Commandsd on the default settings
shows the bias.
Reply all
Reply to author
Forward
0 new messages