Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Random Array

843785Dec 6 2008 — edited Dec 11 2008
Ok, so what I need help with is making a random array of "n" numbers, but the numbers cant be duplicated.

right now i have something like
import java.util.Random;

public class testing {
	
	public static void main(String[] args) {
		Random random = new Random();	
		int max = 10;
		int numOfNumbers = 2;	
		int winningTicket[] = new int[max];
		for (int i = 0; i < numOfNumbers; i++){
			//+1 to eliminate 0, and get the max number given
			winningTicket[i] = random.nextInt(max) + 1;
		}
	}
}
but this code will give duplicate numbers sometimes. how do i solve this problem?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 8 2009
Added on Dec 6 2008
10 comments
220 views