如何在R中生成不同长度的密码?

要生成密码,我们可以使用stringi包的stri_rand_strings函数。 如果我们要使用不同长度的密码,则需要使用特定大小分别创建密码。 例如,对于密码的大小或长度等于8,我们可以在stri_rand_strings函数中使用参数length。

加载stringi包:

> library(stringi)

Example1

> stri_rand_strings(n=5,length=8,pattern="[0-9a-zA-Z]")

[1] "YkIEDYQz" "t42JCzYO" "rOE9YN8U" "2lu9AonY" "6lDUxScX"

Example2

> stri_rand_strings(n=20,length=8,pattern="[0-9a-zA-Z]")

[1]   "glH3ysoX" "X0Sgvg3F" "P3YOePTa" "45GOb2hA" "tLCwszus" "CerCi1ks"

[7]   "UtFwzrSc" "pG8AJCQX" "NTCdMRHj" "5thI1wKb" "Ic8Rol1Y" "JakWa1Wd"

[13]  "9AfeXo7T" "SFJVn9XV" "lIRhLbJ9" "DNFyAbkJ" "jV4jJRZk" "IthkzfEU"

[19]  "talj9nBq" "Nak9Tidh"

Example3

> stri_rand_strings(n=50,length=8,pattern="[0-9a-zA-Z]")

[1]  "89VmsNM8" "RFfLrksc" "3J8vRUYU" "yTgG4ayM" "ocQ9PFwZ" "qqIkoaDu"

[7]  "irwgXwkZ" "6fgz4E3h" "SL67dG6S" "64CQx07J" "cJXWSfnd" "MjrvCVXM"

[13] "rb1JEZPh" "XlskPKui" "Mf3WYw39" "Qka2VPym" "g8COU6yp" "LnhRgjm7"

[19] "1ovSJp8n" "q8klajQM" "f2pcPQ3N" "PxO5Muj4" "VttbR2LP" "IDkwXJpX"

[25] "VP8OfFOs" "peQMeKuQ" "dZMKqQXX" "gax6mTM4" "miZj2zTM" "ZwzjZF4X"

[31] "vBNqPl9j" "rw4XAHzJ" "Jm9J3nzk" "uCfa9qWx" "Yt2KxbH5" "L1REfNl7"

[37] "18IUkwaZ" "geDUOjFb" "TEgMpCcZ" "Bxvz3z2A" "JO2TVQHG" "501pmEVK"

[43] "pUCP9ihO" "BWA0z8IZ" "rMsa6p5V" "t1V0W1z1" "HkyeUdXf" "ISbrs2Ih"

[49] "zdg1v8Pa" "ZCgAIaYv"

Example4

> stri_rand_strings(n=50,length=10,pattern="[0-9a-zA-Z]")

[1]  "J9X0JoERU7" "103F1Vq0OI" "g39YPQBEkp" "kXAHypa3Zd" "QM3nSkdig8"

[6]  "6F8xJAsD0s" "dfX4s2GkO6" "458YGpSUzB" "T6BKhxN126" "yenbIj5yVC"

[11] "UCC5mU90MG" "TlmopiuP16" "US5DVZ5Dvz" "cwGxtfY9qD" "y8t85tpM2v"

[16] "7Xq2k1s0EE" "tXjQYY9pg4" "2ZP4JQDW9r" "PC8YeGfUk0" "Wsl2CzONsg"

[21] "bqmZjxkqgP" "kjiBK8ckxs" "qArKSEzFmf" "qf8wMElHaH" "80TzEEqcVm"

[26] "N4bC6ZVl1F" "HvjCu8Be1b" "kwOFJKeOnw" "LjjHvTKXOD" "PKl2Z1oOIQ"

[31] "xAQli56RM5" "Sp6apwIGpd" "q576G40D3p" "CZY3Qei48E" "yQmnqWbFCP"

[36] "XMMXjJ7Ofc" "I1B4fUto82" "9vCz0ngtc0" "MriEZhGSIe" "9oMibdBWoK"

[41] "NNINTVb4iO" "KRc5RSXv2Z" "UFfM6mNJ4c" "E9DYRlTyko" "K6PXLciTMN"

[46] "VALJzE5bup" "fBlsyDGWhc" "bHmeePU7zC" "mXWAuJ3PU6" "PrNaQozU8Y"

Example5

> stri_rand_strings(n=50,length=6,pattern="[0-9a-zA-Z]")

[1]  "hXiz4Z" "tJ9wUh" "4lePiq" "an3biP" "RZNnBz" "YnUPdV" "MRFYmX" "G8oA4T"

[9]  "mMfAjo" "QWWSmf" "xZUZ0G" "6Ajzs4" "yCR0sp" "4chRxo" "VTcWy0" "jXD4p6"

[17] "PhJqTI" "ssY5ru" "O5kD96" "9A8xTK" "NeuJ1j" "bxHI29" "ZeRKYT" "JZkc70"

[25] "Hxdzbu" "G4jIcW" "50jhzU" "pHzWRC" "EP6N3r" "IwRnsI" "VWvqN1" "7F1pgC"

[33] "yFTIua" "Tpf0eo" "1ypUlR" "zAMWba" "ie1zZa" "FuHonA" "eHxlgL" "owSVGu"

[41] "VmSHDM" "aWNSAD" "wjBTFN" "sjPTlB" "CFHOgM" "2KLDFJ" "hbgLo6" "Fir14n"

[49] "nDjAZH" "ovJjXA"

Example6

> stri_rand_strings(n=50,length=5,pattern="[0-9a-zA-Z]")

[1]  "daKuB" "4ZGPa" "5asVq" "IoWCk" "Vf3tA" "5Siwy" "xfJG1" "3sL1u" "gRn5Z"

[10] "NQr9u" "QTFAQ" "JOY5V" "LBqWN" "xv4dU" "hFFRg" "cwnS6" "ycRMz" "1icDi"

[19] "HcpW2" "B2qBO" "h1o2E" "3fFT1" "SbgaU" "4RgLl" "7Ub41" "Ml8pk" "qclEC"

[28] "X3mdf" "9Gi1e" "e5sBQ" "bp9Av" "NpQ13" "VJcVD" "wxaOl" "gXkBa" "Yf9Gf"

[37] "HsCWN" "JVDOW" "tmcoH" "OtAag" "SoUdC" "OfAuG" "iSuUK" "jTiz0" "UcA88"

[46] "98I0M" "YOQ5G" "ASMtA" "NCOYE" "i4ROS"

Example7

> stri_rand_strings(n=50,length=12,pattern="[0-9a-zA-Z]")

[1]  "CszpavUmKIfb" "stASbW8Yv4NQ" "x0ZkM5CLHT01" "gac0SbvSR7DC" "Vm9YgEKiJ5ru"

[6]  "WE3EPMx2H6B3" "wqtI5FKYId4M" "mkGZHTOM8yVB" "32YQTYRBohfX" "jxWo9LM6TZX8"

[11] "bSfPZCw0iBNy" "6LImEE8auuui" "uktLy3nFc269" "zvlOOXuzBA8W" "wraHzMmX8KDe"

[16] "6nbikPSlCxVC" "OYSecdtr5fDt" "Mu8paw3c6DrZ" "J1s4Gfot2i2l" "9xo6bUOCKrXu"

[21] "BhzTLmF2hnSw" "Ut2hYIFKE0Zf" "7phBKwGqr0tv" "USYJVEJMgtdI" "NO4FZVNRH61g"

[26] "s8f3XD8IwLwI" "ncilwHVqcH62" "U51U2WfpTuJl" "mgADAtOpEjEU" "EzKCjwcTR6Jy"

[31] "IBuDrCW9wWeJ" "HDL1Nh9twm0r" "BYXvBfZnlinO" "2Ui1wtvwN9Me" "vCwkGcdyxg25"

[36] "I2UnP2F4xF8D" "udv7uTsLg0Rk" "z4MlowzMaweP" "XTkzx2AmHZlO" "NmwGAnnHKIUW"

[41] "dRmn8oSAhslH" "yBZBMTdLBbAo" "DypCE7reAZfG" "O37dd0DUOgZs" "MfwXEocuWyqj"

[46] "j865c4y6MYtc" "WBNnsM3tIUxj" "LDxrmUhUC5NA" "6tshejWYSNqx" "20CRiYUC83ml"

Example8

> stri_rand_strings(n=50,length=9,pattern="[0-9a-zA-Z]")

[1]  "mHD3Ji2eh" "Y7y8Ub0PL" "8tkhqVqBO" "pIgadbly8" "45KHL2p2f" "MDWheiVk1"

[7]  "oUa4twIc1" "SgSufZvfD" "sELBDDv5d" "crHkjFIVU" "AGS08JEex" "8kDBmqgUx"

[13] "feKtgk1F4" "gauqUBHOI" "gfyc88S87" "iPqgEwg9D" "WrQt5puLE" "iHLaKybCR"

[19] "JY6jzpjBh" "bVQFViDGN" "aIP5qUxdQ" "2o4zv0ay6" "7gOH0lm3W" "CmVftCoCS"

[25] "20LzR2OmP" "QUXy621AV" "u5hDaOJyd" "xrILUCSAX" "CvdIc41oK" "W4u3PtieR"

[31] "WEtkoGSOK" "cM4zKdjeR" "BCrM0E3JI" "Vrr1kAfR0" "32Riginki" "9fYGpTt0D"

[37] "fKZN6Wg8Q" "zVAfhomYv" "e56IdMPRo" "BcsQRwxSY" "gbHbwoOU5" "eFV4XLxXd"

[43] "MNwQEgmvH" "bsYVvj8ZB" "oFPTZfSzt" "WPAjOq8T4" "H0c1robrz" "wjVRB8GMx"

[49] "lTdGdxkTT" "k3LNYskhB"

以上是 如何在R中生成不同长度的密码? 的全部内容, 来源链接: utcz.com/z/347111.html

回到顶部