The Artima Developer Community
Sponsored Link

Java Answers Forum
Array List

2 replies on 1 page. Most recent reply: May 2, 2002 12:24 PM by Matt Gerrans

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
Anna

Posts: 1
Nickname: ann4
Registered: May, 2002

Array List Posted: May 1, 2002 2:53 PM
Reply to this message Reply
Advertisement
Please help me to solve this problem :
1. How to create 10 random float number without range?
2. And how to store 10 float number in the Array list?
Can I do like this:
float number = (float)(Mth.random*??)
ArrayList array = new ArrayList ();
for(int i=0; i<11,i++)
{
array(i)=(float)(Mth.random*??)

}
please help me.thank's


Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: Array List Posted: May 1, 2002 3:03 PM
Reply to this message Reply
Selvey,
Download te API's.
Atop of a page there is an Index...
Click on "R", fourth entry is Random (java.util.Random).
Don't forget to use the seed( System.currentTimeMillis() )

There you will get the methods :
next<PrimitiveType>

Thomas SMETS,
SCJP2, Brussels

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Array List Posted: May 2, 2002 12:24 PM
Reply to this message Reply
Bon Jour Thomas,

If you use the default constructor of Random, you don't need to specify a seed and it will use the current time automatically.

Also, in this case, it might be easier to use Math.random(), which returns a double. However, she was also asking for an unbounded value, while this method as well as the nextFloat() and nextDouble() methods of Random return a value between 0.0 and 1.0. I guess if you want a random number in the range of all doubles (or floats) then you could multiply the result of this random value by Double.MAX_VALUE (or Float.MAX_VALUE, as it were). This approach is probably statistically flawed, but it is probably close enough for homework. Also, if you want both positive and negative values, you could first subtract 0.5 from the random result, or you could do another call to the random number generator to decide positive/negative.

Flat View: This topic has 2 replies on 1 page
Topic: FileBrowser in Webpage Previous Topic   Next Topic Topic: XML

Sponsored Links



Google
  Web Artima.com   

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