ArrayList draw = new ArrayList();
Random cards = new Random();
public int RandomCards()
{
bool mark = false;
int val = 0;
while (mark == false)
{
val = RandomC();
bool flags = CardCheck(val);
if (flags == true)
{
mark = true;
draw.Add(val);
}
}
return val;
}
public int RandomC()
{
return cards.Next(1, 52);
}
private bool CardCheck(int random)
{
for (int i = 0; i < draw.Count; i++)
{
int calc = (int)draw[i];
if (random == calc)
{
return false;
}
}
return true;
}
This is code from a blackjack applicatiion I did a while ago.
This part is the random I used to draw new cards.
RandomCards runs through selecting a random card(between 1 and 52), after selecting the random card it checks an arraylist draw to see if the card is in the arraylist already, if it is in the arraylist it then selects a new random card and checks it again, until the card does is not in the arraylist, then it adds it to the arraylist ensuring that it cannot be selected again.
Now you can use this method of ensuring that each digit in the number is unique. also using the same method on the number should work, if you have it nested(i.e) you request the number to be generated, then while generating the number you have each digit of the number checked and added, then after you have the required length of digits you can check and add the number as to a different arraylist.
I hope this helps you get on the right track to solve the problem.