Generate Random Emails

Generate random emails

You need random string generator. This answer I stole from here.

protected String getSaltString() {
StringBuilder salt = new StringBuilder();
Random rnd = new Random();
while (salt.length() < 10) { // length of the random string.
int index = (int) (rnd.nextFloat() * SALTCHARS.length());
String saltStr = salt.toString();
return saltStr;


Call it as getSaltString()+"" in you code

How do I generate random email addresses in test.check?

When I run this script:

clojure -Sdeps '{:deps {org.clojure/test.check {:mvn/version "1.1.0"}}}' /dev/stdin <<EOF

(require '[clojure.test.check.generators :as gen])

(def gen-email
(gen/fmap (fn [[s1 s2]] (format "" s1 s2))
(gen/tuple gen/string-alphanumeric

(run! prn (gen/sample gen-email))

I get this output:


How to generate unique random emails with nodemailer

After looking the source code of nodemailer I found there is a cache you can disabled by ETHEREAL_CACHE=false. This generates new emails every time.

Generate random email address and hide form field

You can track whether the value is generated with a data attribute (ex: <input ... data-generated="1" />)

When generated you can set the input to disabled so that the user cannot change the value (ex: <input ... disabled />)

so the generated state for the input would look like:

<input type="text" id="email-field" name="email" 
value="" data-generated="1" disabled>

clicking the button again would reset the input back to

<input type="text" id="email-field" name="email" value="">


$('#random-hold').on('click','.generate-random', () => {
let email = $('#email-field');
if ('generated') === '1') {
} else {
email.val(Math.floor(Math.random() * 1000000000) + "");'generated', '1');
email.attr('disabled', 'disabled');

Alternatively, you might consider doing all this without jQuery, using vanilla Javascript/ES6.

document.querySelector('.generate-random').addEventListener('click', () => {
let email =;
if (email.getAttribute('data-generated') === '1') {
email.value = '';
} else {
email.value = Math.floor(Math.random() * 1000000000) + "";
email.setAttribute('data-generated', '1');
email.setAttribute('disabled', 'disabled');

After generating a random email address, I want to be able to use that same generated email address again

It's very simple. You just need to save the randomly generated email address in a variable and then reuse it again & again whenever you want. All you have to do is:

var randomEmail= chars[Math.floor(Math.random()*26)] 
+ Math.random().toString(36).substring(2,11)
+ '';
return $browser.findElement($"brokers_register_main_broker_username"))

Generating random email addresses (more efficient append)

You can generate your three-digit number at once, instead of generating three separate digits. Remember to format the number, so when it generates value of 0, you will get "jhumphr000" instead of "jhumphr0"

Random random = new Random();
int number = random.nextInt(1000);
String randoms = String.format("%03d", number);

Related Topics

Leave a reply