如何随机是System.Random在.NET 3? [英] How random is System.Random in .NET 3?

查看:178
本文介绍了如何随机是System.Random在.NET 3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在写一个简单的密码生成器(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.

如果你正在考虑滚动您自己,该网站的 <一个href="http://www.guidanceshare.com/wiki/.NET_Framework_2.0_Security_Inspection_Questions_-_Cryptography"相对=nofollow>开发人员指南分享 的有一些信息来说服你出来吧。

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

这篇关于如何随机是System.Random在.NET 3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆