mercredi 24 août 2016

How to generate 1000 unique email-ids using java

My requirement is to generate 1000 unique email-ids in Java. I have already generated random Text and using for loop I'm limiting the number of email-ids to be generated. Problem is when I execute 10 email-ids are generated but all are same.

Below is the code and output:

public static void main() {
    first fr = new first();
    String n = fr.genText()+"@mail.com";

    for (int i = 0; i<=9; i++) {
        System.out.println(n);
    }
}

public String genText() {
    String randomText = "abcdefghijklmnopqrstuvwxyz";
    int length = 4;
    String temp = RandomStringUtils.random(length, randomText);
    return temp;
}

and output is:

myqo@mail.com
myqo@mail.com
...
myqo@mail.com

When I execute the same above program I get another set of mail-ids. Example: instead of 'myqo' it will be 'bfta'. But my requirement is to generate different unique ids.

For Example:

myqo@mail.com
bfta@mail.com
kjuy@mail.com




Aucun commentaire:

Enregistrer un commentaire