I try to print out 6 random numbers from 40 numbers ex( 20,5,1,40,31,29) the program which I have writen is ok, but I don't want that the program writes a random number more than one time. ex 20,5,1,40,31,29) is ok ex 20,5,5,40,31,29) is wrong. // how do I fix it?
Once a number has been selected, set it to -1 (or some other invalid value). Before displaying a number, make sure it's valid. Otherwise, select another.
<a href="http://www.catb.org/~esr/faqs/smart-questions.html" target="_blank" rel="nofollow">How To Ask Smart Questions</a>
What does your code look like? How do you store those 40 numbers in your program; in an array or one of the Java collections?
If you have the numbers in a java.util.List, you can use the method java.util.Collections.shuffle(...) to shuffle the elements in the list, and then you just take the first 6 numbers out of the shuffled list.