dear sir, I am very doubtful in generating a random number within the range selected. for eg, i wants to generate50 random number start from 0000. please advise me! following is my sample of random in java: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ i am using two method: 1) using min and max, my result generated gives me negative value and duplication of the same value occured as well. 2) using NumInt, count,result is also the same as above. I am doubtful in ways to solve duplication occured and negative value. Please advise me..thanks
regards, peiyoon (edited by Cindy to format code) [This message has been edited by Cindy Glass (edited September 13, 2001).]
peiyoon, Please change your name to be compliant with JavaRanch's naming policy. Your ID should be 2 separate names with more than 1 letter each. We really want this to be a professional forum and would prefer that you use your REAL name. Thanks, Cindy
"JavaRanch, where the deer and the Certified play" - David O'Meara
Try the nextInt method in java.util.Random. From the sun site:
public int nextInt(int n) Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence. The general contract of nextInt is that one int value in the specified range is pseudorandomly generated and returned. All n possible int values are produced with (approximately) equal probability...
[This message has been edited by christopher foran (edited September 13, 2001).]
Please ignore post, I have no idea what I am talking about.