Java Random String randomString(int len)

Here you can find the source of randomString(int len)

Description

random String

License

Apache License

Declaration

public static String randomString(int len) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    public static final char[] letters = { 'A', 'T', 'G', 'C' };
    public static Random rand = new Random();

    public static String randomString(int len) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < len; i++) {
            sb.append(randomLetter());//  w w  w .ja  v  a  2s.  c  om
        }
        return sb.toString();
    }

    public static char randomLetter() {
        return letters[rand.nextInt(letters.length)];
    }
}

Related

  1. randomNumberString(int in)
  2. randomRealisticUnicodeString(Random r)
  3. randomString()
  4. randomString()
  5. randomString(final int length)
  6. randomString(int length)
  7. randomString(int length)
  8. randomString(int length)
  9. randomString(int length)