maya wrote:
hi,
am trying to find out how to use random() method.. what is construction
if, say, I want to generate a random no. betw. 1 and 100..
here,
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Math.html#random()
it does not show how this method is used exactly (i.e., what
construction is exactly... these detailed method-sections should show
exact constructions/examples of how method is used..)
this method apparently takes no arguments, so how do you tell it in what
range (betw what nos.) you want the random no. generated?
int randomNo = 0;
randomNo = Math.random(a no. betw. 1 and 100...) // how do you do
this????
AND: if I want to look up java tutorial on this, how do you search for
class, method, etc.. you want here?
http://java.sun.com/docs/books/tutorial/
(a few years ago I had a pg bookmarked in java.sun that was a huge index
to all aspects of Java language, so all you had to do was search for
term you wanted by doing ctrl-find on the browser (or scrolling down..)
(also, this tutorial is for Java 6, do they still have tutorial for
1.5??)
thank you...
what I actually want is to generate a LIST of nos, between 1 and a
variable.. I found this way:
for (int i=1; i <= iPhotosL; i++) {
out.println((int)(Math.random()*iPhotosL) + " -- random
no.<br>");
}
however, I would like to tell it to NOT REPEAT a no. in the list, i.e.,
what I want is a list betw. 1 and a given no., but that no number
appears more than once in the list.. is this possible??
(I want to have option of displaying photos in a random order instead of
in order of img-names (1.jpg, 2.jpg, 3.jpg, etc..))
thank you very much..
Collections.shuffle() with that list object as the parameter.