Dealing with random numbers and arrays in Java
Posted on 2003-03-25
I am creating a program that generates 6 random numbers between 1 and 48; however, the 6 numbers must not match. For example (4, 26, 5, 9, 47, 2);
I had success in generating random numbers, but at times my numbers would come out matching like so ( 4, 34, 5, 4, 32, 1). In C programming I know you could simply use "srand(Time(NULL))" to eradicate this problem, but in Java I can't find a way to do this. I want to avoid using many if statements.
I was told to use two for loops, first one to generate my numbers, and the second one to check them. My numbers are stored in an array, if that helps.
If you have any suggestions I would appreciate them.