The Artima Developer Community
Sponsored Link

Java Answers Forum
Random pages in Java

2 replies on 1 page. Most recent reply: Aug 15, 2003 6:02 AM by David

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Jeff

Posts: 1
Nickname: seitzer
Registered: Aug, 2003

Random pages in Java Posted: Aug 14, 2003 6:49 PM
Reply to this message Reply
Advertisement
I'm looking to set up a page with a random layout at each refresh, with personalized content suiting each version, so far I'm thinking about going with a series of

Math.random()}

Variables to pick a random number (There seems to be a very limited random number generation system), and according to the number the layout is varied.

I'm VERY new to Java and I'm just trying to convert C\C++ coding knowledge over.
Any help or (much) better suggestions are greatly appreciated.


Mr Plow

Posts: 18
Nickname: mrplow
Registered: Jun, 2003

Re: Random pages in Java Posted: Aug 15, 2003 12:07 AM
Reply to this message Reply
Jeff -

java.lang.Math.random() "Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0" (From the Java 1.4.1 API)

Therefore by using a statement like:
int randInt = (int)(Math.random() * 100) + 1;
you can get a random integer value between 1 and 100.

Alternatively, you could create an instance of java.util.Random, and then use the methods nextInt(), nextLong(), nextFloat(), nextDouble() to get a random number of the appropriate type.

David

Posts: 150
Nickname: archangel
Registered: Jul, 2003

Re: Random pages in Java Posted: Aug 15, 2003 6:02 AM
Reply to this message Reply
Here's a link to the JavaDoc:

http://java.sun.com/j2se/1.3/docs/api/java/lang/Math.html

Flat View: This topic has 2 replies on 1 page
Topic: JSP - Bean - SQL Previous Topic   Next Topic Topic: I am getting a nullpointer exception

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use