Jump to content

  • Log In with Google      Sign In   
  • Create Account


[java] Random numbers in JDK 1.1


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Viking   Members   -  Reputation: 122

Like
Likes
Like

Posted 29 June 2000 - 03:30 AM

Hello, I use random numbers in one of my applets I am currently developing. I am using Forte4Java and everthing works fine. But when it comes to open the file in the browser I fail to get it going. As far as I figured it out the line (I snipped the rest) int diceRoll = r.nextInt(maxNumber) + 1; is the problem. Anyone got an idea how to get around this? thanks in advance Juergen

Sponsor:

#2 Jim_Ross   Members   -  Reputation: 122

Like
Likes
Like

Posted 29 June 2000 - 03:49 AM

1.1 doesn''t have any method

java.util.Random.nextInt(int n);

only

java.util.Random.nextInt();

Here''s how java 1.2 does it''s nextInt(int n) method


public int nextInt(int n) {
if (n<=0)
throw new IllegalArgumentException("n must be positive");

if ((n & -n) == n) // i.e., n is a power of 2
return (int)((n * (long)next(31)) >> 31);

int bits, val;
do {
bits = next(31);
val = bits % n;
} while(bits - val (n-1) < 0);
return val;
}



#3 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 29 June 2000 - 03:54 AM

Get Jdk 1.2 or 1.3, you are wasting your time with 1.1

and if you are going to use the random method, don''t forget to import java.util.* unless you like to type

#4 Wrathnut   Members   -  Reputation: 370

Like
Likes
Like

Posted 29 June 2000 - 06:47 AM

I''m not too awful sure which version this comes from, but the Math class has a psuedo random number generating function.. it''s just Math.random() If you are looking for a more sophisticated random number generation technique, like a guassian there is the Random class, where you can use
Random.setSeed(long seed); and
Random.nextGaussian();

But like I said I''m not sure which version of the java sdk supports this.

War doesn't determine who is right, war determines who is left.

#5 Viking   Members   -  Reputation: 122

Like
Likes
Like

Posted 29 June 2000 - 07:43 PM

Thanks for your help. I know I am wasting my time with JDK 1.1 and I already code in JDK 1.3. But as I mentioned earlier I am about to write an applet and AFAIK Netscape 4.7 and IE 5.01 only support JDK 1.1 (well to be exact: the JVM only supports JDK 1.1)

I downloaded and tried the Mozilla browser and the JVM update for IE and now it works on both browsers. BUT I have to ask: Do I really want users of my applet have to download plug-ins or new browsers just to get it going ?

I have no idea when I will be finished with the applet - maybe the JVM''s of the browsers support JDK1.2+ until then :-)

thanks again for your help

Juergen

#6 ManaSink   Members   -  Reputation: 122

Like
Likes
Like

Posted 30 June 2000 - 01:38 AM

1.3 comes with the Java Plugin so you can run Java2 classes in a standard browser. Get the HTML converter to change your web pages to use the plugin.

http://java.sun.com/products/plugin/1.3/features.html

IMHO, coding in 1.1 is not a waste of time if you need to run applets without plugin. It is a deployment issue. A pluggable design that runs under 1.1 or Java2, but takes advantage of Java2 features if it is present may be a good move for you. (The beauty of dynamic class loading...)

ManaSink

#7 Wrathnut   Members   -  Reputation: 370

Like
Likes
Like

Posted 30 June 2000 - 05:30 AM

I have to agree with ManaSink, JDK 1.1 definitly isn''t a waste of time. IMO most people don''t want to download a plugin and you can still achieve the same effects with 1.1 as you can with most of the other SDK''s it just depends on how much time you want to spend writing compatible code. ^_^ my $.02

War doesn't determine who is right, war determines who is left.

#8 Jim_Ross   Members   -  Reputation: 122

Like
Likes
Like

Posted 30 June 2000 - 11:29 AM

And if they guy that signs your checks uses a Mac, you can''t very well tell him to "go get the plugin" when there isn''t a 1.2 plugin for macs. Well, you can, but that usually results in you not getting paid.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS