随机数生成 [英] Random Number Generating

查看:121
本文介绍了随机数生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个程序,在1-10个

之间产生5个非重复的随机数,因为字符串值存储在一个数组中。


有人知道吗任何好的书籍或网站解释如何使用asp.net生成

随机数?我知道.net中的随机命名空间,

但是

我需要引用一些执行上述类似功能的代码。


Plus如果您对上面定义的项目有任何编码练习的想法

请分享它们。


谢谢!

I need a program that generate 5 non-duplicates random number between 1-10
as string values store in an array.

Do anybody know of any good books or websites that explain how to generator
random numbers using asp.net? I know about the random namespace within .net,
but
I need a reference to some code that do the similar stated function above.

Plus If you have any coding practice ideas for the above defined project
please share them.

Thanks!

推荐答案

Leon,


我会使用Random类来执行此操作。它通常会播出时间




如果你需要一个加密安全的随机数发生器,那么<​​br />
查看

System.Security.Cryptography命名空间中的RNGCryptoServiceProvider类。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse。 com


" Leon" < VN ***** @ msn.com>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP15.phx.gbl ...
Leon,

I would use the Random class to do this. It seeds itself off the time
normally.

If you need a cryptographically secure random number generator, then
check out the RNGCryptoServiceProvider class in the
System.Security.Cryptography namespace.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Leon" <vn*****@msn.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
我需要一个程序产生5个非重复的随机数,在1-10之间随着字符串值存储在一个数组中。

任何人都知道任何好书或网站解释如何
生成器
使用asp.net的随机数?我知道
.net中的随机命名空间,但是
我需要引用一些代码,这些代码执行上面类似的陈述功能。

如果你有任何编码实践的想法对于上面定义的项目
请分享。

谢谢!
I need a program that generate 5 non-duplicates random number between 1-10
as string values store in an array.

Do anybody know of any good books or websites that explain how to
generator
random numbers using asp.net? I know about the random namespace within
.net, but
I need a reference to some code that do the similar stated function above.

Plus If you have any coding practice ideas for the above defined project
please share them.

Thanks!



Leon< vn *****@msn.com>写道:
Leon <vn*****@msn.com> wrote:
我需要一个程序,在数组中存储5个非重复的随机数,因为字符串值存储在数组中。

有人知道吗任何好的书籍或网站,解释如何使用asp.net生成随机数?我知道.net中的随机命名空间,
但我需要引用一些代码来执行上面类似的陈述功能。
I need a program that generate 5 non-duplicates random number between 1-10
as string values store in an array.

Do anybody know of any good books or websites that explain how to generator
random numbers using asp.net? I know about the random namespace within .net,
but I need a reference to some code that do the similar stated function above.




如果你''真的只是在十分之五后,我建议有一系列的b / b $ 10布尔值来说明这个数字是否一直被选中,一个

数组结果,并继续选择一个新的随机数,直到

你找到一个之前没有被选中的,将其标记为已选择,

并添加它的字符串表示形式到输出数组。这样做直到

你有5个号码,你就完成了。


如果这还不够,请详细说明你有哪些麻烦。


-

Jon Skeet - < sk * **@pobox.com>
http://www.pobox.com/ 〜双向飞碟

如果回复小组,请不要给我发邮件



If you''re really just after 5 out of 10, I''d suggest having an array of
10 booleans to say whether or not the number has always been picked, an
array of results, and just keep picking a new random number until
you''ve found one which hasn''t been picked before, mark it as picked,
and add its string representation to the output array. Do that until
you''ve got 5 numbers, and you''re done.

If that''s not enough to go on, please give details of which bit you''re
having trouble with.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


嗨Jon,


我有点理解你在说jon,但是请给我一个

的例子吗?


一组10个布尔值?你的意思是随机类只搜索那个是假的数字

,如果是的话它被选中了吗?

将它的字符串表示添加到输出数组?所以我应该有两个

阵列一次搜索,一个将所选值存储为字符串

这样做直到你有5个数字?循环直到我有五个不重复的

ramdon数字?


谢谢!

" Jon Skeet [C#MVP]" ; < SK *** @ pobox.com>在消息中写道

新闻:MP ************************ @ msnews.microsoft.c om ...
Hi Jon,

I kind of understand what you are saying jon, but could please give me an
example?

Array of 10 booleans? you mean the random class would only search the number
that are false, if true it has been picked right?
Add its string representation to the output array? so I should have two
arrays one search and one store the picked values as strings
Do that until you''ve got 5 numbers? Loop until I have five non-duplicate
ramdon numbers?

Thanks!
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Leon< vn ***** @ msn.com>写道:
Leon <vn*****@msn.com> wrote:
我需要一个程序,在字符串值存储在一个数组中时,生成5个非重复的随机数。

有没有人知道任何好的书籍或网站,解释如何使用asp.net生成
随机数?我知道
.net,
中的随机命名空间,但是我需要引用一些代码,这些代码执行上面类似的声明功能。
I need a program that generate 5 non-duplicates random number between
1-10
as string values store in an array.

Do anybody know of any good books or websites that explain how to
generator
random numbers using asp.net? I know about the random namespace within
.net,
but I need a reference to some code that do the similar stated function
above.



如果你真的只是在十分之五的时候,我会建议你使用一系列的10个布尔值来说明这个数字是否总是被选中,结果是一系列结果,以及只需继续选择一个新的随机数,直到你找到一个之前没有被选中的数字,将其标记为已选,
并将其字符串表示添加到输出数组。这样做直到
你有5个数字,并且你已经完成了。

如果这还不够,请详细说明你的位数有麻烦的。

-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复该群组,请不要邮寄我也是



If you''re really just after 5 out of 10, I''d suggest having an array of
10 booleans to say whether or not the number has always been picked, an
array of results, and just keep picking a new random number until
you''ve found one which hasn''t been picked before, mark it as picked,
and add its string representation to the output array. Do that until
you''ve got 5 numbers, and you''re done.

If that''s not enough to go on, please give details of which bit you''re
having trouble with.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too



这篇关于随机数生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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