Java AtomicLong generateRandom()

Here you can find the source of generateRandom()

Description

Generates a random String.

License

Open Source License

Return

a random string

Declaration

public static String generateRandom() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Date;

import java.util.concurrent.atomic.AtomicLong;

public class Main {
    /**//from  ww  w.jav a 2 s. c om
     * Counter used in combination with a timestamp to make random string.
     */
    private static final AtomicLong ATOMIC_COUNT = new AtomicLong();

    /**
     * Generates a random String. Can be useful for creating unique URLs by adding the String as a query parameter to
     * the URL.
     *
     * @return a random string
     */
    public static String generateRandom() {
        long next = ATOMIC_COUNT.incrementAndGet();
        StringBuffer random = new StringBuffer();
        random.append(new Date().getTime()).append('-').append(next);
        return random.toString();
    }
}

Related

  1. createObjectID()
  2. createUniqueFileName(String out)
  3. currentDate()
  4. generateId()
  5. generateId()
  6. get(T stat, AtomicIntegerFieldUpdater updater, boolean reset)
  7. getAndAddCap(AtomicLongFieldUpdater updater, T instance, long n)
  8. getAndAddRequest(AtomicLong requested, long n)
  9. getAndAddRequest(AtomicLongFieldUpdater requested, T object, long n)