随机数的最佳种子 [英] The Best Seed for Random Numbers

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

问题描述

我知道默认情况下随机数生成器使用时间,但是我可以在我的网络应用程序中使用的最佳种子是什么?


程序生成6个唯一的随机数,并在

文本框控件中加载它们。我需要一个好的种子,如IP地址或其他东西。


''生成随机数的函数


公共函数GetRandomNumber()As Integer


Dim objRandom As New System.Random


返回objRandom.Next(1,26)


结束功能

I know by default the random number generator use the time, but what is the
best seed I can used in my web application?

The Program generate 6 unique random numbers and load each of them in a
textbox control. I need a good seed like ip address or something.

''Function to generate random numbers

Public Function GetRandomNumber() As Integer

Dim objRandom As New System.Random

Return objRandom.Next(1, 26)

End Function

推荐答案



" Leon" < VN ***** @ msn.com>在消息中写道

新闻:Ox ************** @ TK2MSFTNGP11.phx.gbl ...

"Leon" <vn*****@msn.com> wrote in message
news:Ox**************@TK2MSFTNGP11.phx.gbl...
我默认知道随机数生成器使用时间,但是什么是
我可以在我的网络应用程序中使用的最佳种子?

程序生成6个唯一的随机数并在
文本框控件。我需要一个好的种子,如IP地址或其他东西。

''生成随机数的函数

公共函数GetRandomNumber()作为整数

昏暗objRandom As New System.Random

返回objRandom.Next(1,26)

结束功能
I know by default the random number generator use the time, but what is the best seed I can used in my web application?

The Program generate 6 unique random numbers and load each of them in a
textbox control. I need a good seed like ip address or something.

''Function to generate random numbers

Public Function GetRandomNumber() As Integer

Dim objRandom As New System.Random

Return objRandom.Next(1, 26)

End Function



我不是知道这是否是最佳但我使用(这是一个随机数

字符串格式)另外你可以将8改为更高的数字更大的


Dim strID as string = DateTime.Now.Ticks.tostring()

Dim rdm1 as Random

rdm1 = new Random(ctype(right(strID,8),int32))

strUnique = rdm1.next()。tostring()


I don''t know if this is best or not but I use (this is for a random number
in string format) Also you can change the 8 to a higher number for a larger
random number.

Dim strID as string = DateTime.Now.Ticks.tostring()
Dim rdm1 as Random
rdm1 = new Random(ctype(right(strID,8),int32))
strUnique = rdm1.next().tostring()


为什么选择ticks(long)并将其作为字符串转换为仅将其转换为

整数?

为什么只选择正确的8个字符而不是整个值?


将myRandom调暗为新随机(CType(Now.Ticks,Integer))


将theNumber调暗为Intege r = myRandom.Next
Why take ticks (long) and cast as a string only to cast it back to an
Integer?
Why take only the right 8 chars and not the whole value?

Dim myRandom As New Random(CType(Now.Ticks, Integer))

dim theNumber as Integer = myRandom.Next


我不知道这是不是最好但是我用(这个是字符串格式的随机数
也可以将8更大的数字更改为更大的
随机数。

Dim strID as string = DateTime.Now.Ticks.tostring()
Dim rdm1 as Random
rdm1 = new Random(ctype(right(strID,8),int32))
strUnique = rdm1.next()。 tostring()


I don''t know if this is best or not but I use (this is for a random number
in string format) Also you can change the 8 to a higher number for a
larger
random number.

Dim strID as string = DateTime.Now.Ticks.tostring()
Dim rdm1 as Random
rdm1 = new Random(ctype(right(strID,8),int32))
strUnique = rdm1.next().tostring()





" Scott M." < S - *** @ nospam.nospam>在留言中写道

新闻:%2 **************** @ tk2msftngp13.phx.gbl ...

"Scott M." <s-***@nospam.nospam> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
为什么选择ticks(long)并作为一个字符串强制转换为
整数?
为什么只选择正确的8个字符而不是整个值?

Dim myRandom As新的随机(CType(Now.Ticks,整数))
将数字调整为整数= myRandom.Next
Why take ticks (long) and cast as a string only to cast it back to an
Integer?
Why take only the right 8 chars and not the whole value?

Dim myRandom As New Random(CType(Now.Ticks, Integer))

dim theNumber as Integer = myRandom.Next


我不知道这是不是最好但是我使用(这是一个字符串格式的随机
数字)另外你可以将8更改为更高的数字/>更大
随机数。

Dim strID as string = DateTime.Now.Ticks.tostring()
Dim rdm1 as Random
rdm1 = new Random(ctype (右(strID,8),int32))
strUnique = rdm1.next()。tostring()


I don''t know if this is best or not but I use (this is for a random number in string format) Also you can change the 8 to a higher number for a
larger
random number.

Dim strID as string = DateTime.Now.Ticks.tostring()
Dim rdm1 as Random
rdm1 = new Random(ctype(right(strID,8),int32))
strUnique = rdm1.next().tostring()



我这样做因为我想要一个16个字符的字符串,后来在

代码(不包括在内)中添加了剩下的人物。另外我想如果你使用

整个刻度它对于Random来说太大了。


Well I do this because I wanted a 16 character string and later on in the
code (not included) I add the remaining characters. Also I think if you use
the whole tick it was too big for Random.


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

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