954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

request and question in float random number

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

alsoumhi
Junior Poster in Training
66 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

how about you just store it as an integer which when divided by 20 yields your number?

bugmenot
Posting Whiz in Training
225 posts since Nov 2006
Reputation Points: 53
Solved Threads: 34
 

hi reading from file is not hard. <> may give you some help.

Great_qiang
Newbie Poster
3 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

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

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You