Here you can find the source of rand(int bit)
public static String rand(int bit)
//package com.java2s; //License from project: Open Source License import java.util.Random; public class Main { public static String rand(int bit) { if (bit < 1) { return ""; }/*from w w w. j ava 2 s.com*/ Random random = new Random(); Double randNumber = random.nextDouble(); return randNumber.toString().split("\\.")[1].substring(0, bit); } }