Here you can find the source of getRandomString(final int size)
Parameter | Description |
---|---|
size | the length of the returned random String |
public static String getRandomString(final int size)
//package com.java2s; /*//from w w w.j ava 2 s.c o m * * JMeta - Meta's java implementation * * Copyright (C) 2013-2015 Pablo Joubert * Copyright (C) 2013-2015 Thomas Lavocat * Copyright (C) 2013-2015 Nicolas Michon * * This file is part of JMeta. * * JMeta is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * JMeta 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ import java.util.Random; public class Main { private static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; private static final Random rnd = new Random(); /** * Creates a random alpha-numeric String of given length * * @param size the length of the returned random String * @return the random String */ public static String getRandomString(final int size) { StringBuilder sb = new StringBuilder(size); for (int i = 0; i < size; i++) { sb.append(AB.charAt(rnd.nextInt(AB.length()))); } return sb.toString(); } }