C#随机字母数字字符串? [英] C# random alphanumeric strings ?
问题描述
有人有例子吗?
bitshift写道:
任何人都有一个例子 ?
asdxcgfd
-
Tom Spink
大学of Edinburgh
7月2日下午3:12,bitshift < j ... @ aol.comwrote:
有人举个例子吗?
1)硬编码包含您想要包含的所有字符的字符串
2)使用单个Random实例(适当的)锁定,如果你是
将从许多线程中使用它)
3)创建一个正确长度的StringBuilder
4)In for循环,使用
Random.Next附加下一个随机字符,传入字符串的长度,并使用字符串's
indexer
5)在StringBuilder上调用ToString
Jon
Jon Skeet [C#MVP]写道:
7月2日下午3:12,bitshift < j ... @ aol.comwrote:
>任何人都有一个例子?
1)硬编码包含您想要包含的所有字符的字符串
2)使用单个Random实例(适当的)锁定,如果你是
将从许多线程中使用它)
3)创建一个正确长度的StringBuilder
4)In for循环,使用
Random.Next附加下一个随机字符,传入字符串的长度,并使用字符串's
indexer
5)在StringBuilder上调用ToString
Jon
Jon Jon,
伟大的思想相似。
-
Tom Spink
爱丁堡大学
Anyone got an example ?
bitshift wrote:
Anyone got an example ?asdxcgfd
--
Tom Spink
University of Edinburgh
On Jul 2, 3:12 pm, "bitshift" <j...@aol.comwrote:Anyone got an example ?1) Hard-code a string with all the characters you want to include
2) Use a single instance of Random (with appropriate locking if you''re
going to use it from many threads)
3) Create a StringBuilder of the right length
4) In a for loop, append the next random character by using
Random.Next, passing in the string''s length, and using string''s
indexer
5) Call ToString on the StringBuilder
Jon
Jon Skeet [C# MVP] wrote:
On Jul 2, 3:12 pm, "bitshift" <j...@aol.comwrote:>Anyone got an example ?
1) Hard-code a string with all the characters you want to include
2) Use a single instance of Random (with appropriate locking if you''re
going to use it from many threads)
3) Create a StringBuilder of the right length
4) In a for loop, append the next random character by using
Random.Next, passing in the string''s length, and using string''s
indexer
5) Call ToString on the StringBuilder
JonHi Jon,
Great minds think alike.
--
Tom Spink
University of Edinburgh
这篇关于C#随机字母数字字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!