Maybe it is not best solution. Try to use random number generator for integers. Generate randomly the number from 1 to 9. Then generate second number and compare it with previous one. If it coincide, generate one more and so on till you get four different numbers. After that repeat this procedure and check whether new number is coincided with existed ones if you need that.