request and question in float random number

Reply

Join Date: Aug 2007
Posts: 63
Reputation: alsoumhi is an unknown quantity at this point 
Solved Threads: 0
alsoumhi alsoumhi is offline Offline
Junior Poster in Training

request and question in float random number

 
0
  #1
Dec 28th, 2007
Hi guys hope you fine
I have a request and question, for my request I would like from you to recommend me
which books and tutorials that I may follow help me to understand how to read and write files in java I really need to know that. and for my question is how to make a float random ends with five or zero only. For example 0.25 , 0.30 , 0.35 , 0.40 , 0.45 ,0.50 , 0.55 , and so on till number one. I don't need a float numbet appears to me such as 0.23 , 0.14 , 0.78 , 0.99 , 0.61 , 0.12 , etc ... so how it's done that


thanks,
my regard
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 224
Reputation: bugmenot is an unknown quantity at this point 
Solved Threads: 31
bugmenot bugmenot is offline Offline
Posting Whiz in Training

Re: request and question in float random number

 
-1
  #2
Dec 28th, 2007
how about you just store it as an integer which when divided by 20 yields your number?
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 3
Reputation: Great_qiang is an unknown quantity at this point 
Solved Threads: 0
Great_qiang's Avatar
Great_qiang Great_qiang is offline Offline
Newbie Poster

Re: request and question in float random number

 
0
  #3
Dec 29th, 2007
hi reading from file is not hard. <<Thinking java>> may give you some help.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: request and question in float random number

 
0
  #4
Dec 30th, 2007
I would do it as such. Assuming you want the floating number to be displayed to only 2dp.
  • I would first, generate an integer between 1-9, then divide it by 10.
  • Then I would have a second random function that generates either 0.05 or 0.0
  • I would then add the two together.

So for example:-

7 / 10 = 0.7
0.05
0.7 + 0.05 = 0.75
Last edited by iamthwee; Dec 30th, 2007 at 12:31 pm.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC