I am a newbie to
java and I made this little program called "UniqueRandom". Please suggest ways to improve this code or point out any bad practices, errors etc.
INTRO :
Aim : This class CAN be used to generate each number from a given range only once in a random order, ie not necessarily increasing or decreasing.
______________________________________________________________________________________________________________________________________
HOW IT WORKS :
public void setData(int first, int last)
-Takes range from user.
-fills the numbers in that range into an array list.
public int random( )
-math.random() picks an index ("rand") from above array list and stores the number at rand in a temporary variable "num" .
Then it deletes the number at index rand. Return num.
-call this method as many times as you like, provided you dont demand more numbers than are in the generator.
main() to
test the code.
______________________________________________________________________________________________________________________________________
THE CODE :
THE OUTPUT :
thanks for reading patiently.
regards
rb
PS: Taken great pains to make this as convenient to read as possible. Please put a small reminder in your mind and review this if you can find the time or are in the mood for random stuff.