使用26个字母(含大小写,实际为52个字母)和10个数字组合一个4位的串码,问有多少种组合?

'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'

一.从数学角度推导出组合公式

组合数公式是指从 n 个不同元素中,任取 m(m≤n) 个元素并成一组,叫做从 n 个不同元素中取出 m 个元素的一个组合;从 n 个不同元素中取出 m(m≤n) 个元素的所有组合的个数,叫做 n 个不同元素中取出 m 个元素的组合数。用符号 C(n,m) 表示。

以数字集合n1,取m个元素做组合,该集合内无重复元素(有重复元素就要先去重)

n1 = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }

此例可初步推导出,在n个无重复元素集合中,取m个元素做组合(长度为x,组合时可复用单个元素),组成为不同的串码组合,可以有n的m次方(n^m或n^x)种组合;

此处n1=10,m=4;

由上得出C(n,m)=n1的m次方=n1^m=10^4=10000;

若n1=10,m=3;

得出C(n,m)=n1^m=10^3=1000;

二.使用java程序实现组合结果,并输出(此DEMO程序没有做去重复元素的逻辑实现)

/*** Copyright (C), 2000-2021, XXX有限公司* FileName: combination* Author: wangyetao* Date: 21-10-20 11:20:40* Description: 组合学:26个字母(含大小写)和10个数字组合为4位串的可能性测算* History:* <author> <time> <version> <desc>* 作者姓名 修改时间 版本号 版本描述*/
package simple.callback.cryptographyalgorithm;/*** @ClassName: combination* @Description: java类描述* @Author: wangyetao* @Date: 21-10-20 11:20:40*/
public class Combination {//四个数组,实际可用递归代替,这里只做直观的演示用private static char[] charLibs0 = new char[]{/*'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', */'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};private static char[] charLibs1 = new char[]{/*'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', */'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};private static char[] charLibs2 = new char[]{/*'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', */'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};private static char[] charLibs3 = new char[]{/*'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', */'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};//标位1//标位2//标位3//标位4//计数private static int count = 0;//TESTpublic static void main(String[] args) {for (int i = 0; i < charLibs0.length; i++) {for (int j = 0; j < charLibs1.length; j++) {for (int k = 0; k < charLibs2.length; k++) {for (int l = 0; l < charLibs3.length; l++) {System.out.println(charLibs0[i] + "" + charLibs1[j] + "" + charLibs2[k] + "" + charLibs3[l]); //输出单次组合结果count++;}}}}System.out.println("count:" + count);}}

程序输出0(仅数字的组合):

0000
0001
0002

......

9997
9998
9999
count:10000

Process finished with exit code 0

程序输出1(仅小写字母的组合):

......
zzzw
zzzx
zzzy
zzzz
count:456976

Process finished with exit code 0

程序输出2(大小写字母+数字的组合):

count:14776336

Process finished with exit code 0

在此记录与总结,如有错误请指正,感谢!2021年 10月 20日 星期三 13:11:32 CST。

UPDATE1,2021年 10月 20日 星期三 18:04:15 CST

simple.callback.cryptographyalgorithm.CombinationV2.java

/*** Copyright (C), 2000-2021, XXX有限公司* FileName: CombinationV2* Author: wangyetao* Date: 21-10-20 15:10:31* Description:组合学:26个字母(含大小写)和10个数字组合为4位串码的可能性测算V2* History:* <author> <time> <version> <desc>* 作者姓名 修改时间 版本号 版本描述*/
package simple.callback.cryptographyalgorithm;import java.util.ArrayList;/*** @ClassName: CombinationV2* @Description: java类描述* @Author: wangyetao* @Date: 21-10-20 15:10:31*/
public class CombinationV2 {//字符数组private static char[] charLibs = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};//单例实例对象private static CombinationV2 instance = null;//存储所有生成的组合,一次装载到内存,也可通过其它中间件方式;volatile+同步锁,确保多线程环境下数据安全private volatile static ArrayList<String> libs = new ArrayList();//记数private static int count = 0;//标位private volatile static int nextIndex = -1;//获取组合串码的总个数public int libsize() {return libs.size();}private CombinationV2() {}//获取单例public static CombinationV2 getInstance() {//class同步锁synchronized (CombinationV2.class) {if (instance == null) {long startTime = System.currentTimeMillis();init();instance = new CombinationV2();long consumeTime = System.currentTimeMillis() - startTime;System.out.println("首次创建单例实例对象耗时:" + consumeTime + "ms");}return instance;}}/*** 初始化生成并保存所有的不重复的4位串码组合* 此处暂用FOR嵌套实现。题外话:看有些技术社区文章说可用递归实现*/private static void init() {for (int i = 0; i < charLibs.length; i++) {for (int j = 0; j < charLibs.length; j++) {for (int k = 0; k < charLibs.length; k++) {for (int l = 0; l < charLibs.length; l++) {libs.add(count, charLibs[i] + "" + charLibs[j] + "" + charLibs[k] + "" + charLibs[l]);count++;}}}}}//取串码public String next() {synchronized (CombinationV2.class) {if (libs != null && libs.size() > 0) {nextIndex++;if (nextIndex < libsize()) {return libs.get(nextIndex);}}}return "";}//标位重置public void indexReset() {synchronized (CombinationV2.class) {nextIndex = -1;}}}

simple.callback.cryptographyalgorithm.CombinationV2Test.java

/*** Copyright (C), 2000-2021, XXX有限公司* FileName: CombinationV2Test* Author: wangyetao* Date: 21-10-20 17:09:56* Description:测试用例* History:* <author> <time> <version> <desc>* 作者姓名 修改时间 版本号 版本描述*/
package simple.callback.cryptographyalgorithm;import org.junit.Test;import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;/*** @ClassName: CombinationV2Test* @Description: 测试用例类* @Author: wangyetao* @Date: 21-10-20 17:09:56*/
public class CombinationV2Test {@Testpublic void testCombinationV2() throws InterruptedException {}public static void main(String[] args) {ExecutorService cachedThreadPool = Executors.newCachedThreadPool();Runnable runnable = new Runnable() {@Overridepublic void run() {task();}};//50*3=150cachedThreadPool.execute(runnable);cachedThreadPool.execute(runnable);cachedThreadPool.execute(runnable);cachedThreadPool.shutdownNow();cachedThreadPool.shutdown();}//5*5*2=50public static void task() {CombinationV2 combinationV2 = CombinationV2.getInstance();CombinationV2 combinationV21 = CombinationV2.getInstance();System.out.println("Thread-" + Thread.currentThread().getName() + "-libsize=" + combinationV2.libsize());for (int i = 0; i < 5; i++) {for (int j = 0; j < 5; j++) {System.out.println("Thread-" + Thread.currentThread().getName() + "-combinationV2:" + combinationV2.next());System.out.println("Thread-" + Thread.currentThread().getName() + "-combinationV21:" + combinationV21.next());}}}
}

DEMO输出结果:

首次创建单例实例对象耗时:15952ms
Thread-pool-1-thread-1-libsize=14776336
Thread-pool-1-thread-2-libsize=14776336
Thread-pool-1-thread-3-libsize=14776336
Thread-pool-1-thread-2-combinationV2:0001
Thread-pool-1-thread-1-combinationV2:0000
Thread-pool-1-thread-1-combinationV21:0004
Thread-pool-1-thread-1-combinationV2:0005
Thread-pool-1-thread-2-combinationV21:0003
Thread-pool-1-thread-3-combinationV2:0002
Thread-pool-1-thread-3-combinationV21:0008
Thread-pool-1-thread-3-combinationV2:0009
Thread-pool-1-thread-3-combinationV21:000a
Thread-pool-1-thread-3-combinationV2:000b
Thread-pool-1-thread-3-combinationV21:000c
Thread-pool-1-thread-2-combinationV2:0007
Thread-pool-1-thread-1-combinationV21:0006
Thread-pool-1-thread-2-combinationV21:000e
Thread-pool-1-thread-3-combinationV2:000d
Thread-pool-1-thread-2-combinationV2:000g
Thread-pool-1-thread-1-combinationV2:000f
Thread-pool-1-thread-2-combinationV21:000i
Thread-pool-1-thread-3-combinationV21:000h
Thread-pool-1-thread-2-combinationV2:000k
Thread-pool-1-thread-1-combinationV21:000j
Thread-pool-1-thread-2-combinationV21:000m
Thread-pool-1-thread-3-combinationV2:000l
Thread-pool-1-thread-2-combinationV2:000o
Thread-pool-1-thread-1-combinationV2:000n
Thread-pool-1-thread-2-combinationV21:000q
Thread-pool-1-thread-3-combinationV21:000p
Thread-pool-1-thread-2-combinationV2:000s
Thread-pool-1-thread-1-combinationV21:000r
Thread-pool-1-thread-2-combinationV21:000u
Thread-pool-1-thread-3-combinationV2:000t
Thread-pool-1-thread-2-combinationV2:000w
Thread-pool-1-thread-1-combinationV2:000v
Thread-pool-1-thread-2-combinationV21:000y
Thread-pool-1-thread-3-combinationV21:000x
Thread-pool-1-thread-2-combinationV2:000A
Thread-pool-1-thread-1-combinationV21:000z
Thread-pool-1-thread-2-combinationV21:000C
Thread-pool-1-thread-3-combinationV2:000B
Thread-pool-1-thread-2-combinationV2:000E
Thread-pool-1-thread-1-combinationV2:000D
Thread-pool-1-thread-2-combinationV21:000G
Thread-pool-1-thread-3-combinationV21:000F
Thread-pool-1-thread-2-combinationV2:000I
Thread-pool-1-thread-1-combinationV21:000H
Thread-pool-1-thread-2-combinationV21:000K
Thread-pool-1-thread-3-combinationV2:000J
Thread-pool-1-thread-2-combinationV2:000M
Thread-pool-1-thread-1-combinationV2:000L
Thread-pool-1-thread-2-combinationV21:000O
Thread-pool-1-thread-3-combinationV21:000N
Thread-pool-1-thread-2-combinationV2:000Q
Thread-pool-1-thread-1-combinationV21:000P
Thread-pool-1-thread-2-combinationV21:000S
Thread-pool-1-thread-3-combinationV2:000R
Thread-pool-1-thread-3-combinationV21:000V
Thread-pool-1-thread-2-combinationV2:000U
Thread-pool-1-thread-1-combinationV2:000T
Thread-pool-1-thread-2-combinationV21:000X
Thread-pool-1-thread-3-combinationV2:000W
Thread-pool-1-thread-2-combinationV2:000Z
Thread-pool-1-thread-1-combinationV21:000Y
Thread-pool-1-thread-2-combinationV21:0011
Thread-pool-1-thread-2-combinationV2:0013
Thread-pool-1-thread-2-combinationV21:0014
Thread-pool-1-thread-2-combinationV2:0015
Thread-pool-1-thread-2-combinationV21:0016
Thread-pool-1-thread-2-combinationV2:0017
Thread-pool-1-thread-2-combinationV21:0018
Thread-pool-1-thread-2-combinationV2:0019
Thread-pool-1-thread-2-combinationV21:001a
Thread-pool-1-thread-2-combinationV2:001b
Thread-pool-1-thread-2-combinationV21:001c
Thread-pool-1-thread-2-combinationV2:001d
Thread-pool-1-thread-2-combinationV21:001e
Thread-pool-1-thread-2-combinationV2:001f
Thread-pool-1-thread-2-combinationV21:001g
Thread-pool-1-thread-2-combinationV2:001h
Thread-pool-1-thread-2-combinationV21:001i
Thread-pool-1-thread-2-combinationV2:001j
Thread-pool-1-thread-2-combinationV21:001k
Thread-pool-1-thread-2-combinationV2:001l
Thread-pool-1-thread-2-combinationV21:001m
Thread-pool-1-thread-2-combinationV2:001n
Thread-pool-1-thread-2-combinationV21:001o
Thread-pool-1-thread-3-combinationV21:0010
Thread-pool-1-thread-3-combinationV2:001p
Thread-pool-1-thread-3-combinationV21:001q
Thread-pool-1-thread-3-combinationV2:001r
Thread-pool-1-thread-3-combinationV21:001s
Thread-pool-1-thread-3-combinationV2:001t
Thread-pool-1-thread-3-combinationV21:001u
Thread-pool-1-thread-3-combinationV2:001v
Thread-pool-1-thread-3-combinationV21:001w
Thread-pool-1-thread-3-combinationV2:001x
Thread-pool-1-thread-3-combinationV21:001y
Thread-pool-1-thread-3-combinationV2:001z
Thread-pool-1-thread-3-combinationV21:001A
Thread-pool-1-thread-3-combinationV2:001B
Thread-pool-1-thread-3-combinationV21:001C
Thread-pool-1-thread-3-combinationV2:001D
Thread-pool-1-thread-3-combinationV21:001E
Thread-pool-1-thread-3-combinationV2:001F
Thread-pool-1-thread-3-combinationV21:001G
Thread-pool-1-thread-3-combinationV2:001H
Thread-pool-1-thread-3-combinationV21:001I
Thread-pool-1-thread-3-combinationV2:001J
Thread-pool-1-thread-3-combinationV21:001K
Thread-pool-1-thread-3-combinationV2:001L
Thread-pool-1-thread-3-combinationV21:001M
Thread-pool-1-thread-3-combinationV2:001N
Thread-pool-1-thread-3-combinationV21:001O
Thread-pool-1-thread-3-combinationV2:001P
Thread-pool-1-thread-3-combinationV21:001Q
Thread-pool-1-thread-3-combinationV2:001R
Thread-pool-1-thread-3-combinationV21:001S
Thread-pool-1-thread-1-combinationV2:0012
Thread-pool-1-thread-1-combinationV21:001T
Thread-pool-1-thread-1-combinationV2:001U
Thread-pool-1-thread-1-combinationV21:001V
Thread-pool-1-thread-1-combinationV2:001W
Thread-pool-1-thread-1-combinationV21:001X
Thread-pool-1-thread-1-combinationV2:001Y
Thread-pool-1-thread-1-combinationV21:001Z
Thread-pool-1-thread-1-combinationV2:0020
Thread-pool-1-thread-1-combinationV21:0021
Thread-pool-1-thread-1-combinationV2:0022
Thread-pool-1-thread-1-combinationV21:0023
Thread-pool-1-thread-1-combinationV2:0024
Thread-pool-1-thread-1-combinationV21:0025
Thread-pool-1-thread-1-combinationV2:0026
Thread-pool-1-thread-1-combinationV21:0027
Thread-pool-1-thread-1-combinationV2:0028
Thread-pool-1-thread-1-combinationV21:0029
Thread-pool-1-thread-1-combinationV2:002a
Thread-pool-1-thread-1-combinationV21:002b
Thread-pool-1-thread-1-combinationV2:002c
Thread-pool-1-thread-1-combinationV21:002d
Thread-pool-1-thread-1-combinationV2:002e
Thread-pool-1-thread-1-combinationV21:002f
Thread-pool-1-thread-1-combinationV2:002g
Thread-pool-1-thread-1-combinationV21:002h
Thread-pool-1-thread-1-combinationV2:002i
Thread-pool-1-thread-1-combinationV21:002j
Thread-pool-1-thread-1-combinationV2:002k
Thread-pool-1-thread-1-combinationV21:002l
Thread-pool-1-thread-1-combinationV2:002m
Thread-pool-1-thread-1-combinationV21:002n
Thread-pool-1-thread-1-combinationV2:002o
Thread-pool-1-thread-1-combinationV21:002pProcess finished with exit code 0

最后小结:从 n 个不同元素中,任取 m(m≤n) 个元素并成一组(长度为x,组合时可复用单个元素),组成为不同的串码组合,则组合数C(n,m)=n^m或C(n,m)=n^x;
由52个字母与10个数字,组成的4位串码,排列组合数有C(n,m)=n^m=62^4=14776336种。

在此记录与总结,2021年 10月 20日 星期三 18:18:04 CST。

组合学:26个字母(含大小写)和10个数字组合为4位串的可能性测算相关推荐

  1. Java 随机数练习之从26个英文字母(含大小写)和 0 - 9 数字中随机抽出4个字符,然后拼接成一个随机验证码

    从26个英文字母(含大小写)和 0 - 9 数字中随机抽出4个字符,然后拼接成一个随机验证码 判断输入的验证码 与 随机生成的验证码 是否相同(忽略大小写) 如果正确,则系统提示,"恭喜你验 ...

  2. 随机密码生成。编写程序,接收列表在26个字母大小写和10个数字组成的列表中随机生成10个8位密码。

    随机密码生成.编写程序,接收列表在26个字母大小写和10个数字组成的列表中随机生成10个8位密码. 这里我们要用到random函数. 代码如下: import random for i in rang ...

  3. 一、 输出 1~100 之间不能被 7 整除的数,每行输出 10 个数字,要求应用字符 串格式化方法(任何一种均可) 美化输出格式。 输出效果为:

    一. 输出 1~100 之间不能被 7 整除的数,每行输出 10 个数字,要求应用字符 串格式化方法(任何一种均可) 美化输出格式. j=0 for i in range(101): #循环if i& ...

  4. 随机密码生成。编写程序,在26个字母大小写和10个数字组成的列表中随机生成10个8位密码。

    随机密码生成.编写程序,在26个大小写字母和10和数字组成的列表中随机生成10个8位的密码: 根据题目要求,我们编写的程序主干要有哪些内容呢? 1.随机选择 2.26个大小写字母 3.10个阿拉伯数字 ...

  5. python随机密码生成在26个字母中随机生成10个_习题6:二.3 随机密码生成

    编写程序在26个字母大小写和9个数字组成的列表中随机生成10个8位密码. import random num_ls = [] # 创建数字.小写字母.大写字母空列表 str_ls = [] STR_l ...

  6. js正则验证弱密码(大小写,特殊字符,数字不少于8位) element-plus 表单验证

    为了顺应网络安全的要求,前端要在登录的时候验证用户的密码是否为弱密码.特此记录. 密码的校验规则是: 用户密码长度不少于8位,包裹大小写字母.数字.字符中的至少3种,不能包含用户名. 1.开始写出各个 ...

  7. vue正则判断输入0-100之间(含0、100)数字,最多两位(多位)小数

    正则表达式:  /^(([1-9]?\d{0,1}(\.\d{1,2})?)|100|100\.(0){1,2})$/ <el-table-columnlabel="付款金额" ...

  8. c语言辅音字符怎么表示,英语26个字母口诀

    " 第一部分:基础知识 1.字母:26个字母的大小写 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 2.语音:元音的发音 五个元 ...

  9. 随机密码生成。编写程序,在26个字母大小写和9个数字组成的列表中随机生成10个8位密码。

    #e6.1随机密码生成,在26个字母大小写和9个数字组成的列表中随机生成10个8位密码 import random s = ["a","b","c&q ...

最新文章

  1. 接口冲突的一种解决方法
  2. Java计算两个字符串日期之间的天数差
  3. shell实例第11讲:取出系统IP地址,并判断属于哪个网段
  4. 主板rs232接口测试软件,简洁的RS232串口通信电路与串口通信测试程序
  5. javascript中的继承方式
  6. 解决MySQL报错ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘localhost:3306‘ (10061)
  7. 移动端实现文字轮播_js实现移动端轮播图
  8. python socket epoll_python 关于epoll的学习
  9. WAF(NGINX)中502和504的区别
  10. ThinkPHP文件目录说明
  11. 黑暗森林:知识图谱的前世今生
  12. CXF +ws-security 和HttpURLConnection实现webservic请求
  13. linux 安装 yum 命令源
  14. nEO iMAGING——400K的图像处理软件(应急处理照片的好帮手)
  15. 盖洛普 打破一切常规心得体会(汇集)
  16. 财务信息化系统架构设计
  17. 权威证明共识(Proof of Authority)
  18. java 使用CA认证
  19. 与活体检测技术结合的人脸识别技术
  20. 旅游 - 珠海长隆海洋王国 - 鹦鹉过山车

热门文章

  1. 【剑指offer系列】剑指offer 07-10
  2. monkey android 教程,Android Monkey使用详解
  3. Java使用Junit测试控制台输出
  4. 单商户商城b2c基本功能
  5. 15、线程同步方式有哪些?优缺点?
  6. IDEA在terminal使用mvn命令
  7. 博通卖掉赚钱的物联网部门,奥妙在哪里?
  8. 面试造火箭,工作拧螺丝?看下这些大厂原题吧(iOS开发方向)
  9. 【暑假自学C语言】 --8 练习题详解(分段函数)
  10. [ 数据结构-C实现 ] 堆、堆排序的分析及实现