bug in j2me implementation of Random?

K

kloro

bug in j2me Random implementation?
From:
tom arnall <[email protected]>
To:
Date:
Sunday 05:17:49 pm
the following:

public class Test1 extends MIDlet implements CommandListener {

public void startApp() {
Random rand = new Random();
System.out.println(rand.nextInt(5));
}
.
.
.

from the J2me compiler gets:

home/kloro/cell/WTK2.2/apps/Test1/src/Test1.java:11: nextInt()
in
java.util.Random cannot be applied to (int)
System.out.println(rand.nextInt(5));

yet the doc' for Random states in the methods section:

nextInt(int n) - Returns a pseudorandom, uniformly distributed
int value
between 0 (inclusive) and the specified value (exclusive),
drawn from this
random number generator's sequence.

same type of result for long, double, short.
 
P

Patricia Shanahan

kloro said:
bug in j2me Random implementation?
From:
tom arnall <[email protected]>
To:
Date:
Sunday 05:17:49 pm
the following:

public class Test1 extends MIDlet implements CommandListener {

public void startApp() {
Random rand = new Random();
System.out.println(rand.nextInt(5));
}
.
.
.

from the J2me compiler gets:

home/kloro/cell/WTK2.2/apps/Test1/src/Test1.java:11: nextInt()
in
java.util.Random cannot be applied to (int)
System.out.println(rand.nextInt(5));

yet the doc' for Random states in the methods section:

nextInt(int n) - Returns a pseudorandom, uniformly distributed
int value
between 0 (inclusive) and the specified value (exclusive),
drawn from this
random number generator's sequence.

same type of result for long, double, short.

Which documentation are you using for the J2ME API?

Patricia
 
D

Daniel Dyer

bug in j2me Random implementation?
From:
tom arnall <[email protected]>
To:
Date:
Sunday 05:17:49 pm
the following:

public class Test1 extends MIDlet implements CommandListener {

public void startApp() {
Random rand = new Random();
System.out.println(rand.nextInt(5));
}
.
.
.

from the J2me compiler gets:

home/kloro/cell/WTK2.2/apps/Test1/src/Test1.java:11: nextInt()
in
java.util.Random cannot be applied to (int)
System.out.println(rand.nextInt(5));

That method doesn't exist in the J2ME version. The J2ME java.* classes
correspond to JDK 1.1 classes. The nextInt(int) method was introduced in
J2SE 1.2.

If you need this method, you can extend the Random class and add this
method (just cut and paste it from the source of the Java SE version of
java.util.Random).
yet the doc' for Random states in the methods section:

nextInt(int n) - Returns a pseudorandom, uniformly distributed
int value
between 0 (inclusive) and the specified value (exclusive),
drawn from this
random number generator's sequence.
same type of result for long, double, short.

You're reading the wrong version of the documentation, you need the J2ME
docs.

Dan.
 
K

kloro

Daniel said:
That method doesn't exist in the J2ME version. The J2ME java.* classes
correspond to JDK 1.1 classes. The nextInt(int) method was introduced in
J2SE 1.2.

If you need this method, you can extend the Random class and add this
method (just cut and paste it from the source of the Java SE version of
java.util.Random).


You're reading the wrong version of the documentation, you need the J2ME
docs.

following is the url of the doc' section from which i quoted, as set up
by the WTK2.2 installer:


file:///home/kloro/cell/WTK2.2/docs/api/midp/java/util/Random.html#next(int)
 
K

kloro

kloro said:
following is the url of the doc' section from which i quoted, as set up
by the WTK2.2 installer:


file:///home/kloro/cell/WTK2.2/docs/api/midp/java/util/Random.html#next(int)


sorry, make that url:

file:///home/kloro/cell/WTK2.2/docs/api/midp/java/util/Random.html#nextInt(int)
 
T

tom arnll

Patricia said:
Which documentation are you using for the J2ME API?

Patricia


egg on face! i tried it again this a.m. and it works. have no idea of what i
changed to make things different. thanks for your posts.

tom arnall
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top