Java Random String getRandomStringForDate()

Here you can find the source of getRandomStringForDate()

Description

get Random String For Date

License

Open Source License

Declaration

public static String getRandomStringForDate() 

Method Source Code

//package com.java2s;
/*/*w  ww . jav a 2 s  .  c  o  m*/
 * Copyright (c) 2008-2013 Maksim Khadkevich and Fondazione Bruno Kessler.
 *
 * This file is part of MART.
 * MART is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2, as published
 * by the Free Software Foundation.
 *
 * MART is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with MART; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    protected static Random random;

    public static String getRandomStringForDate() {
        if (random == null) {
            random = new Random();
        }
        SimpleDateFormat formatter = new SimpleDateFormat(
                "yyyy-MM-dd-HH-mm-ss-SS");
        String dateStr = formatter.format(new Date());
        return String.format("%s_%d", dateStr,
                (int) (random.nextFloat() * 1000));
    }
}

Related

  1. getRandomString(Random random, int minLen, int maxLen)
  2. getRandomString(Random random, int totalLength, int randomSectionLength)
  3. getRandomString(Random rnd, int minLength, int maxLength)
  4. getRandomString(String paramString, int paramLength)
  5. getRandomStringByLength(int length)
  6. getRandomStringOfLetters(int length)
  7. getString(int length)
  8. getString(int length)
  9. getString(int length)