Common functions such as Excel random numbers/random letters/random dates/random names

Common functions such as Excel random numbers/random letters/random dates/random names

Randomly select characters from options

=CHOOSE(RANDBETWEEN(1,6), "CA", "XGM", "MSS", "CCS", "SY", "HJ") FROM "CA", "XGM", "MSS", "CCS
" , randomly select one of "SY" and "HJ"

random number

Random integers can be generated using the RANDBETWEEN and RAND functions.

--生成一个 1 到 100 之间的随机整数
=RANDBETWEEN(1,100)
--生成一个 0 到 1 之间的随机小数
=RAND()
--生成一个 0 到 1 之间的随机小数保留两位小数
=ROUND(RAND(),2)
--生成一个 10 到 20 之间的随机保留两位小数的数字
=ROUND(RAND()*(upper_bound-lower_bound)+lower_bound,2)
=ROUND(RAND()*(20-10)+10,2)

random letters

Random letters can be generated using the CHAR and RANDBETWEEN functions. For example, if you want to generate a random capital letter in cell A1, you can use the following formula:

=CHAR(RANDBETWEEN(65,90))

In the above formula, RANDBETWEEN(65,90) generates a random integer between 65 and 90 representing the ASCII codes for the uppercase letters A through Z. CHAR(RANDBETWEEN(65,90)) converts this random integer to the corresponding uppercase letter.

If you want to generate a random lowercase letter, you can use the following formula:

=CHAR(RANDBETWEEN(97,122))

In the above formula, RANDBETWEEN(97,122) generates a random integer between 97 and 122, representing the ASCII codes of lowercase letters a to z. CHAR(RANDBETWEEN(97,122)) converts this random integer to the corresponding lowercase letter.

random date/time

random date:

=RANDBETWEEN(DATE(2022,1,1), DATE(2023,12,31))

In the above formula, DATE(2022,1,1) and DATE(2023,12,31) represent January 1, 2022 and December 31, 2023, respectively. The RANDBETWEEN function randomly generates a date between these two dates.

random time:

=TEXT(RAND()*"24:0:0"+"0:0:0","HH:MM:ss")
--或下面这个
=TIME(INT(RAND()*24), INT(RAND()*60), INT(RAND()*60))

In the above formula, RAND()*24, RAND()*60 and RAND()*60 generate a random number between 0 to 23, 0 to 59 and 0 to 59 respectively, representing hours, minutes and seconds. The INT function rounds these random numbers down to integers. Finally, the TIME function converts these integers to a time value.

Note: In the data type cell, the '0' before '01' will be deleted, and only '1' will be kept. Therefore, if you want to generate a random date with & splicing, you need to set the cell format to "00"

random name

=MID($B$2,ROUND(RAND()*LEN($B$2),0)+1,1)&MID($B$3,ROUND(RAND()*LEN($B$3),0)+1,1)&IF(RAND()>0.3,MID($B$3,ROUND(RAND()*LEN($B$3),0)+1,1),"")

Place the following data in cells B2 and B3 respectively

赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐费廉岑薛雷贺倪汤滕殷罗毕郝邬安常乐于时傅皮卞齐康伍余元卜顾孟平黄和穆萧尹姚邵湛汪祁毛禹狄米贝明臧计伏成戴谈宋茅庞熊纪舒屈项祝董梁杜阮蓝闵席季麻强贾路娄危江童颜郭梅盛林刁锺徐邱骆高夏蔡田樊胡凌霍虞万支柯昝管卢莫
骏宇玄璀紫子全超益莉信美奎琪豪浩槐文巧治瑜雯诗涵曦嵘天誉喜伟嘉欣卿钰勇寅天宸兵祥运昊泽仁淳轩子泳瑶源杰正驿豪财熙海辉辉天华峻龙嘉璐娅琦晶妍茹清吉克茜秋珊莎锦黛青倩婷姣婉娴瑾颖露瑶怡婵雁蓓纨仪荷丹蓉眉君琴蕊薇菁梦岚苑婕馨瑗琰韵融园艺咏卿聪澜纯毓悦昭冰爽琬茗羽希宁欣飘育涵琴晴丽美瑶梦茜倩希夕月悦乐彤影珍依沫玉灵瑶嫣倩妍萱漩娅媛怡佩淇雨娜莹娟文芳莉雅芝文晨宇怡全子凡悦思奕依浩泓钊钧铎谦亨奇固之轮翰朗伯宏先柏镇淇淳一洁铭皑言若鸣朋斌梁栋维启克伦翔旭鹏泽晨辰士以建家致树炎德行时泰盛雄琛钧冠策腾楠榕风航弘瑛玲憧萍雪珍滢筠柔竹霭凝晓欢霄枫芸菲寒伊亚宜可姬舒影荔枝丽秀娟英华慧巧美静淑惠珠莹雪琳晗瑶允元源渊和函妤宜云琪勤珍贞莉兰凤洁琳素云莲真环雪荣爱妹霞亮香月媛艳瑞凡佳嘉叶璧

Reminder

Since most of the random functions are volatile functions, that is, whenever the worksheet is changed, it will recalculate and generate a new random data. So if you want to keep the generated random data, you can copy and paste it into other tables in the form of values

Insert a magic command

dir /b /s windows to traverse the directory
shift + right-click the subline text column to edit

Guess you like

Origin blog.csdn.net/qq_43605229/article/details/127583836
Recommended