Php直播源码,获取随机数,随机字符串

2020-11-19 11:29:25 浏览数 (1)

PHP直播源码,获取随机数,随机字符串的相关代码

代码语言:javascript复制
private void randomTest() {
    Random random = new Random();
    Log.e(TAG, "randomTest1: "   random.nextLong());
    Log.e(TAG, "randomTest2: "   random.nextBoolean());
    Log.e(TAG, "randomTest3: "   random.nextDouble());
    Log.e(TAG, "randomTest4: "   random.nextFloat());
    Log.e(TAG, "randomTest5: "   random.nextGaussian());//可以产生服从高斯分布的随机数
    Log.e(TAG, "randomTest6: "   random.nextInt());
    //范围内的随机数
    int min = 10;
    int max = 99;
    int num = random.nextInt(max - min   1)   min;
    Log.e(TAG, "randomTest7: "   num);
}
/**
 * 获取一条随机字符串
 * @param length
 * @return
 */
public String getRandomString(int length) { //length表示生成字符串的长度
    String base = "abcdefghijklmnopqrstuvwxyz0123456789";
    Random random = new Random();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < length; i  ) {
        int number = random.nextInt(base.length());
        sb.append(base.charAt(number));
    }
    Log.e(TAG, "getRandomString: "   sb.toString());
    return sb.toString();
}

以上就是PHP直播源码,获取随机数,随机字符串的相关代码, 更多内容欢迎关注之后的文章

0 人点赞