如何随机是System.Random在.NET 3?System、Random、NET

由网友(眉眼如故)分享简介:我目前正在写一个简单的密码生成器(C#)。为此,我需要一些随机数。I am currently writing a simple password generator (C#). For that I need some random numbers.是否确定要简单地使用随机类随.NET或是否有任何已知的问题是什么...

我目前正在写一个简单的密码生成器(C#)。为此,我需要一些随机数。

I am currently writing a simple password generator (C#). For that I need some random numbers.

是否确定要简单地使用随机类随.NET或是否有任何已知的问题是什么?

Is it OK to simply use the Random class that ships with .NET or are there any known problems with that?

推荐答案

没有什么不妥之处 - 它足以产生简单的密码。一个简单的例子(源):

There is nothing wrong with it -- it's good enough to generate simple passwords. A simple example (source):

Random RandomClass = new Random();
int RandomNumber = RandomClass.Next(); // Random number between 1 and 2147483647
double RandomNumber = RandomClass.Next(1,10); // Random number between 1 and 10

double RandomDouble = RandomClass.NextDouble(); // Random double between 0.0 and 1.0

这篇文章的 如何:生成一个随机密码(C#/ VB.NET) 的有一个非常COM prehensive产生很好的例子,易于读取指定的复杂密码。这可能是矫枉过正你,但它可能会提供从创意复制一个很好的来源。

The article How To: Generate a Random Password (C#/VB.NET) has a very comprehensive example of generating good, easy-to-read passwords with specified complexity. It may be overkill for you, but it might provide a nice source to copy ideas from.

如果你需要更多的东西的密码,还有另外一个命名空间为:

If you need something more for cryptography, there's another namespace for that:

System.Security.Cryptography

具体而言,可以使用这样的:

Specifically, you can use this:

System.Security.Cryptography.RNGCryptoServiceProvider.GetBytes(yourByte)

一个例子是的 使用加密在VB中的随机数.NET 的,另一种是 加密随机数 的。

An example is Using Crypto for your Random Numbers in VB.NET, and another one is Crypto Random Numbers.

如果你正在考虑滚动您自己,该网站的 开发人员指南分享 的有一些信息来说服你出来吧。

If you're thinking about rolling your own, the site Developer Guidance Share has some information to talk you out of it.

阅读全文

相关推荐

最新文章