hi Could any one tell me whether any practical diff. bet the Math.random and java.util.Random class. I understand that Math.random() is a static method & it is shared by all who r accessing it. But using java.util.Random, i can create new instance every time. any other difference??? thanx in adv. luv, Augg
I checked the source code, and the "Math.random()" method does a lazy (on-demand) instantiation of a "java.util.Random" instance the first time it's invoked. Then it simply calls the "nextDouble()" method. So Math.random() is simply a wrapper around "java.util.Random".
Joined: Sep 23, 2003
Hi, Thanx for ue reply. I do not understand what u mean by the word on-demand instantiation. When i say "new A()", then JVM has to create a new instance of A, right??? Could u pls explain this in detail??? luv, Augg