please help, im trying to assign a random number variable which ive created called 'custID' in a Customer Class to an array list of customers called 'customerList' which is in the program.
How can I do this?
Any help is appreciated.
Thanks
Printable View
please help, im trying to assign a random number variable which ive created called 'custID' in a Customer Class to an array list of customers called 'customerList' which is in the program.
How can I do this?
Any help is appreciated.
Thanks
First off, if you are trying to use random numbers to generate unique id's.. don't. Use a GUID.
Anyway, look at the Random class.
Code:Random rnd = new Random();
System.Collections.ArrayList rndID = new System.Collections.ArrayList();
int numsID = 20;
int minID = 1;
int maxID = 100;
for (int c = 1; c <= numsID; c++)
{
rndID.Add(rnd.Next(minID, maxID));
}
thanks for the feedback - i've been told to use array list so i'm guessing i have to.
I have an arraylist called customerList and all i want to do is give each of the customers a Random number
so that when i execute the command to display all the customers in that array, it displays its ID alongside each individual customer.
Ive researched GUID's and they would have been ideal but they are too long and Random numbers are sure to be fine as its just a mini project with a few customers in the array.