preventing same random numbers in JAVA
This is actually something I need help with in a java assignment. But I am pretty sure the concept is similar to C++. In other words if you know C++ you can probably help me with this minor set back.
I basically want to generate random numbers (from 0 to 9). However I do not want it to generate duplicate random numbers. I have been messing around with this for a few hours but still can not come up with something to prevent the recurring of the same numbers. for example I do not want this......8, 8, 3, 5, 6. Where 8 is duplicated. I do not want that. Below is a snippet of part of my assignment that I have been messing around with trying to prevent this problem. So far I am stumped.
Code:
for (int i = 0 ; i < lotteryNumbers.length; i++)
{
lotteryNumbers[i] = rN.nextInt(9);
for(int x = 1; x < lotteryPicks.length; x++)
{
if (lotteryNumbers[i] == lotteryNumbers[x])
{
lotteryNumbers[x] = rN.nextInt(9);
}
}
}
Thank you