求大佬帮忙

5:10 2020-03-28 05:06:21
用java,生成十组随机六位数代码
...全文
100 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
ethanzhl 2020-03-28
  • 打赏
  • 举报
回复
int count = 0; while (count < 11){ System.out.println(RandomStringUtils.random(6)); ++ count; }
Little5 2020-03-28
  • 打赏
  • 举报
回复

	/**
	 * 0~9 a~z A~Z 随机字符串生成器
	 * 
	 * @param scale
	 *            字符串长度
	 * @param count
	 *            字符串数量
	 * @return 结果集合
	 * @date 2020-03-28 19:38:07
	 */
	public static List<String> RandomStr(int scale, int count)
	{
		StringBuilder sb = new StringBuilder();
		String strNum = "0123456789";
		String strCh = "abcdefghijklmnopqrstuvwxyz";
		sb.append(strNum).append(strCh).append(strCh.toUpperCase());// 0~9 a~z A~Z

		List<String> res = new ArrayList<>();
		int index = 0;
		char[] ch = new char[scale];
		while (0 != count--)
		{
			for (int i = 0; i < ch.length; i++)
			{
				index = (int) (Math.random() * sb.length());// 生成0 到 sb.length()-1的随机数
				ch[i] = sb.charAt(index);
			}
			res.add(String.valueOf(ch));
		}
		return res;// 大小为count
	}
System.out.println(RandomStr(6, 10));
// [uY73SU, 1etcqK, WsBbT6, 5w73l3, dB5Zz1, mJQaHA, 4r1nBy, KKDLLZ, NKHMjR, KwjfW0]
5:10 2020-03-28
  • 打赏
  • 举报
回复
引用 8 楼 源者鬼道的回复:
[quote=引用 5 楼 Little5的回复:][quote=引用 1 楼 源者鬼道 的回复:]

                Random rand = new Random();
		for(int i=0; i<10; i++) {
			System.out.print(rand.nextInt(1000000) + " ");
		}
记得结帖哦
你这有问题哈,别人要的是全部6位数的。[/quote] 执行一下可以试试,出来的应该都是六位数的,[/quote] 不是都是六位数
源者鬼道 2020-03-28
  • 打赏
  • 举报
回复
引用 5 楼 Little5的回复:
[quote=引用 1 楼 源者鬼道 的回复:]

                Random rand = new Random();
		for(int i=0; i<10; i++) {
			System.out.print(rand.nextInt(1000000) + " ");
		}
记得结帖哦
你这有问题哈,别人要的是全部6位数的。[/quote] 执行一下可以试试,出来的应该都是六位数的,
源者鬼道 2020-03-28
  • 打赏
  • 举报
回复
执行一下可以试试,出来的应该都是六位数的
Little5 2020-03-28
  • 打赏
  • 举报
回复
引用 1 楼 源者鬼道 的回复:

                Random rand = new Random();
		for(int i=0; i<10; i++) {
			System.out.print(rand.nextInt(1000000) + " ");
		}
记得结帖哦
你这有问题哈,别人要的是全部6位数的。
源者鬼道 2020-03-28
  • 打赏
  • 举报
回复
引用 3 楼 weixin_46383888的回复:
[quote=引用 1 楼 源者鬼道的回复:]

                Random rand = new Random();
		for(int i=0; i<10; i++) {
			System.out.print(rand.nextInt(1000000) + " ");
		}
记得结帖哦
怎么加上含大小写字母的啊,大哥[/quote] 使用数组,随机获得下标实现字符的随机获得
5:10 2020-03-28
  • 打赏
  • 举报
回复
引用 2 楼 Little5的回复:
这样?
		int[] arr = new int[10];
		int res = 0;
		for (int i = 0; i < arr.length; i++)
		{
			res = 100000 + (int) (Math.random() * 900000);
			arr[i] = res;
		}
可加上大小写字母吗
5:10 2020-03-28
  • 打赏
  • 举报
回复
引用 1 楼 源者鬼道的回复:

                Random rand = new Random();
		for(int i=0; i<10; i++) {
			System.out.print(rand.nextInt(1000000) + " ");
		}
记得结帖哦
怎么加上含大小写字母的啊,大哥
Little5 2020-03-28
  • 打赏
  • 举报
回复
这样?
		int[] arr = new int[10];
		int res = 0;
		for (int i = 0; i < arr.length; i++)
		{
			res = 100000 + (int) (Math.random() * 900000);
			arr[i] = res;
		}
源者鬼道 2020-03-28
  • 打赏
  • 举报
回复

                Random rand = new Random();
		for(int i=0; i<10; i++) {
			System.out.print(rand.nextInt(1000000) + " ");
		}
记得结帖哦

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧