RANDOM NUMBER GENERATION IN MIDP

lexander Bosco

Ranch Hand

Posts: 65

posted 12 years ago

hey ppl am having a challenge generatin random numbers , the java.lang MATH class has no implementation of the random method() and the java.util.Random class generates numbers in thousands rather dan in 10s. and what is wrong with the java.util.Random nextDouble() method ? when i use it the builder tells me e.g: i use it this way = Random rd = new Random(); double top = rd.nextDouble();

there is no knowledge that is not power<br />-<br />SCJP 1.4<br />SCWCD in progress<br />SCMAD in progress

Shawn Fitzgerald

author
Greenhorn

Posts: 25

posted 12 years ago

Question: when is the random object returning in 1000's and not 10's? Is that on the nextInt(int n) method? The 'n' value is how many bits to support in the low order values. so for values under 100 you might have to go to 128, or things under 10 you may have to go to 16, and then skip values greater than the limit you are looking for.

in the case of nextDouble, you must be using a CLDC1.0 implementation. 'double' was not supported until CLDC1.1, before that you had no option to use double or float only int and long. How to find this out, look in java.lang.Double in the J2ME javadocs, and you will see a 'since' tag that states when the component was introduced. The primatives were not introduced before the wrapper classes so checking the wrapper dates will tell you when the primative type was introduced or if it is available.

You might just need to turn on in the WTK the CLDC1.1 requirement and re-build your project.