This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Math.random().....what is the starting range ad ending range?can we customise the range numbers ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Math.random().....what is the starting range ad ending range?can we customise the range numbers ? " Watch "Math.random().....what is the starting range ad ending range?can we customise the range numbers ? " New topic
Author

Math.random().....what is the starting range ad ending range?can we customise the range numbers ?

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1050

whats the starting and ending range when we use Math.random() can we customise the range numbers


http://www.lifesbizzare.blogspot.com || OCJP:81%
shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
Math.random() randomly generates values of type double between 0.0000 to 1.000 including the boundary values. now using this you can generate all randome values by using an appropriate multiplier

like

5.0 * Math.random() would generate random values between 0.00 to 5.00
300 * Math.random() would generate random values between 0.00 to 300.00

its very simple, i dont know why would you need to customise its range
Adomin Hoghog
Greenhorn

Joined: Jan 31, 2010
Posts: 4
Between 0.0 and 1.0. Hint:you can multiply+cast the result to get a wellformed int.
Java 6 API docs
Misha van Tol
Ranch Hand

Joined: Jan 02, 2010
Posts: 56

Its greater than or equal to 0.0 and less than 1.0.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
One of you is correct. If you had looked in the API you would have known the correct answer.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10908
    
  12

you can multiply and add to get just about any range you want. if you need something between 10-20, that's the same as getting a value from 0-10 and adding 10 to it. So, you multiply by the RANGE of values you need, then add (or subtract) an offset (if needed. You can then round to an int, if that is needed.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Math.random().....what is the starting range ad ending range?can we customise the range numbers ?
 
Similar Threads
customising the included content with jsp:param
How to choose a random no in a specific range?
Use of Math.random
Random number
Math.random