get Random Number - Android java.util

Android examples for java.util:Random

Description

get Random Number

Demo Code

public class Main{

    private static String getRandomNum(int length) {
        length = (length > 0) ? length : 10;
        StringBuffer sRand = new StringBuffer();
        for (int i = 0; i < length; i++) {
            sRand.append((int) (Math.random() * 10));
        }/*from  w  w w  .j  av  a 2s .  c  om*/
        return sRand.toString();
    }

}

Related Tutorials