trying to duplicate some PHP code in C#. The PHP code uses the uniqid function with the more entropy parameter set to true. Any idea of how to best duplicate this in C#?
2条回答 默认 最新
duanrenchuo9244 2009-08-22 13:56关注something like:
string uniqid(string prefix, bool more_entropy) { if(string.IsNullOrEmpty(prefix)) prefix = string.Empty; if (!more_entropy) { return (prefix + System.Guid.NewGuid().ToString()).Left(13); } else { return (prefix + System.Guid.NewGuid().ToString() + System.Guid.NewGuid().ToString()).Left(23); } }Edit: To reflect comments
This is a very simple off the top of my head solution, and I'd suggest that for a more rigorous solution you'd investigate proper 'random' number' generation such as via System.Math namespace directly. Please see these other SO questions and answers on random number generation.
System.Guid.NewGuid().ToString()
Will give you a unique string.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报