在VB.NET中在Rnd()之前使用Randomize() [英] Using Randomize() before Rnd() in VB.NET

查看:331
本文介绍了在VB.NET中在Rnd()之前使用Randomize()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前被告知,在Rnd()之前,应始终使用Randomize() > VB.NET 应用程序.但是,没有它似乎总是可以正常工作.在这种情况下,添加Randomize()对我有什么作用?

I have previously been told that I should always use Randomize() before I use Rnd() in a VB.NET application. Yet, it always seems to work fine without it. What does adding Randomize() do for me in this case?

似乎对我的应用程序影响最小.

It doesn't appear to affect my application in the least.

推荐答案

在Visual Basic中,

In Visual Basic, Rnd() uses a mathematical operation to produce the next "random" number. Because the actual operation is known, given a specific value, you can predict the next value. However, given an arbitray start value the numbers have good distribution - these are "pseudo-random" numbers.

要防止Rnd()以可预测的数字开头(因此每次都给出相同的随机"数字序列),请

To keep Rnd() from startng at a predictable number (and hence giving the same sequence of "random" numbers every time), Randomize() should be called to use the machine clock to set the initial value (called a seed).

(在 .NET 的世界中,我会使用

(In the .NET world, I'd use System.Random instead if you can.)

这篇关于在VB.NET中在Rnd()之前使用Randomize()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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