惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
Microsoft Security Blog
Microsoft Security Blog
云风的 BLOG
云风的 BLOG
B
Blog
The Register - Security
The Register - Security
L
LangChain Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
F
Full Disclosure
The GitHub Blog
The GitHub Blog
Recorded Future
Recorded Future
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Blog — PlanetScale
Blog — PlanetScale
Jina AI
Jina AI
美团技术团队
宝玉的分享
宝玉的分享
Hugging Face - Blog
Hugging Face - Blog
阮一峰的网络日志
阮一峰的网络日志
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
D
DataBreaches.Net
Martin Fowler
Martin Fowler
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
The Cloudflare Blog
博客园 - 【当耐特】
U
Unit 42
月光博客
月光博客
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
博客园 - 聂微东
I
InfoQ
B
Blog RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
Cyberwarzone
Cyberwarzone
V
V2EX
S
Securelist
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Security @ Cisco Blogs
PCI Perspectives
PCI Perspectives
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Heimdal Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Hacker News
The Hacker News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Tor Project blog

博客园 - 暗香浮动

quartz.net 项目无法加载的问题 wcf的诡异问题 获取iTextSharp 的image 报错 FastReport 隐藏matrix的列如何实现 获取FileStream物理文件位置 log4net 1.2.11.0 的一点更新 无法更改数据库最大线程数 Moss文件操作速度慢的问题解决记录 无法更改数据库最大线程数 windows 服务循环任务.服务启动后无法停止重启的解决办法 单用户模式恢复到多用户模式. mssql 数据库还原脚本 让客户ie8浏览器默认使用ie7兼容模式 - 暗香浮动 - 博客园 Package load Analyzer Create two fload when i run vs2008.here is solution to stop this. vss 命令行unpin批量操作 及vss的bug补丁 wf数据库Tracking服务 数据库表详解 截断css影响的问题 clrprofile造成的日志肿瘤问题解决 webconfig中配置log4net 数据访问及业务层使用
生成随机字符串的问题
暗香浮动 · 2009-12-07 · via 博客园 - 暗香浮动

工作中经常需要生成不重复的随机字符串。

使用random来生成的话。短时间内生成的重复太多如这篇文章的  http://www.cnblogs.com/smhy8187/articles/888729.html 

现发现关于重复太多也是有办法解决的  就是Random类定义成 静态类.

和这篇文章的http://www.cnblogs.com/insus/articles/1396908.html 我都试验了。效果都不是很好。

考虑使用 Guid来截取效果可能不错试验了一下效果还可以。如果想使用全部字母的话。可以考虑和前面提到的两个连接的文章结合起来创建到字母表的映射修改一个算法出来。

    class Program
    {
        
static void Main(string[] args)
        {
           
            List
<string> list = new List<string>();
            
int count = 8000, lenght = 6;
            
int had = 0
           
            
while (list.Count < count)
            {
                
for (int i = 0; i < count -had; i++)
                {
                    
string s = Guid.NewGuid().ToString().Replace("-","").Substring(0,lenght);//obj.RandomNumber(true, true, 6);
                    list.Add(s);
                    
                }
                
for (int i = 0; i < list.Count - 1; i++)
                {
                    
for (int j = i + 1; j < list.Count; j++)
                    {
                        
if (list[i].Equals(list[j]))
                        {
                            list.RemoveAt(j);
                            j
--;
                        }
                    }
                }
                had 
= list.Count;
                Console.WriteLine(had);

            }

            Console.Write(list.Count);
            Console.ReadLine();
            
        }
    }