Java Random Email generateRandomEmailAddress(String domain)

Here you can find the source of generateRandomEmailAddress(String domain)

Description

Generates random email address with specified domain

License

Open Source License

Parameter

Parameter Description
domain For example: google.com

Return

Random email address as string

Declaration

public static String generateRandomEmailAddress(String domain) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   w  w w  .j  a  v  a  2  s. com*/
     * Generates random email address with specified domain
     * 
     * @param domain
     *            For example: google.com
     * @return Random email address as string
     */
    public static String generateRandomEmailAddress(String domain) {
        String emailAddress = "";
        // Generate random email address
        String alphabet = "abcdefghijklmnopqrstuvwxyz";
        while (emailAddress.length() < 5) {
            int character = (int) (Math.random() * 26);
            emailAddress += alphabet.substring(character, character + 1);
        }
        emailAddress += Integer.valueOf((int) (Math.random() * 99))
                .toString();
        emailAddress += "@" + domain;
        return emailAddress;
    }
}