Re: Math.random()
- From: maya <maya778899@xxxxxxxxx>
- Date: Mon, 25 Feb 2008 17:24:56 -0500
Hal Rosser wrote:
"maya" <maya778899@xxxxxxxxx> wrote in message news:fpvdus$8de$1@xxxxxxxxxxxoh brother... I think get gist of what you're saying.. will try it....;) thank you very much.. (boolean array.... hmmm.. not sure if I've ever even seen code for a boolean array...;)maya wrote:hi,what I actually want is to generate a LIST of nos, between 1 and a variable.. I found this way:
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...
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..
Create a boolean array 0 to <your max value> and Each time you select a number - set the the array element that has that index to true but keep another variable for the count of how many you want - but only increment the count if the array element was false before you set it to true.
Do the loop until the count equals the number you of picks you wanted.
You're welcome
.
- Follow-Ups:
- Re: Math.random()
- From: Lew
- Re: Math.random()
- References:
- Math.random()
- From: maya
- Re: Math.random()
- From: maya
- Re: Math.random()
- From: Hal Rosser
- Math.random()
- Prev by Date: Re: Math.random()
- Next by Date: Re: Math.random()
- Previous by thread: Re: Math.random()
- Next by thread: Re: Math.random()
- Index(es):
Relevant Pages
|
|