File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java Micro Edition
generating random numbers
Joined: Dec 01, 2004
Feb 05, 2005 01:18:00
how can i generate a random number between specific range, say for example between 1-5??
Teach me to die that so I may<br />Rise glorious at the awful day
Joined: Sep 13, 2003
Feb 05, 2005 13:48:00
You can use
Random rGen = new Random(); int r = rGen.nextInt(); r = 1 + r % 4; // where 1 is the start of your interval // and 4 is the end of the interval minus the start (5-1)
I agree. Here's the link:
subject: generating random numbers
generating unique numbers
how to genrate a random number inside the range
Random number between size of an array
Regarding random number generation.
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015