package suanfa; import java.util.Random; public class RandomStr { public static String getRandomStr(int length) { String base = "abcdefghijklmnopqrstuvwxyz0123456789"; int randomNum; char randomChar; Random random = new Random(); // StringBuffer
//返回一个指定范围内的随机数 function createRandomNum(Min,Max){ let Range = Max - Min; let Rand = Math.random(); return(Min + Math.round(Rand * Range)); } createRandomNum(2,11); //3 //返回一个指定长度的随机字符串 let chars = ['0','1','2','3','4','5','6','7','8','9','A','B','C'
利用Python生成随机域名等随机字符串. #!/usr/bin/env python# -*- coding: utf-8 -*- from random import randrange, choice from string import ascii_lowercase as lc from sys import maxsize from time import ctime tlds = ('com', 'edu', 'net', 'org', 'gov') for i in range(
为了生成更加可靠的随机数,微软在System.Security.Cryptography命名空间下提供一个名为system.Security.Cryptography.RNGCryptoServiceProvider的类,它采用系统当前的硬件信息.进程信息.线程信息.系统启动时间和当前精确时间作为填充因子,通过更好的算法生成高质量的随机数,生成强随机字符串的方法如下所示: using System.Security.Cryptography; sealed class RNGCryptoRand