Basically I have an array full of objects customer, one attribute a customer must have is a unique account number.
//make me a random number generator called 'generator'
Random generator = new Random();
//Set account number to random number
AccountNumber = generator.nextInt(89999);
//Make sure number is 5 digits so if randome number is, 0 + 10000 = 10000
accountNumber = accountNumber + 10000;
Now this creates the random number for the account but I have no way of making it unique.
I thought about listing through all the previous account numbers and then if it was the same then picking a new random number.. something like..
for (int x = 0, customerArray.getlength-1, x++)
{
if accountNumber == customerArray[x].getAccountNumber();
AccountNumber = generator.nextInt(89999);
accountNumber = accountNumber + 10000;
}
I only just roughtly wrote that code down so dont point out any small mistakes i might of made, anyway doing the above method would check through all previous account numbers and if its the same the do a new random number, however the new random number could be the same as an account already passed so this doesnt really help...
anyone here got any ideas
Thanks
alot.. oh in case you can't tell i'm writing this at 12 at night half asleep so im not sure about grammatical errors or the like...