Using Randomize () before Rnd () in VB.NET

I was previously told that I should always use Randomize()before using Rnd()in a VB.NET application . However, it always works fine without it. What does the addition do Randomize()for me in this case?

This app doesn’t seem to affect my app.

+3
source share
3 answers

In Visual Basic, Rnd () uses a mathematical operation to create the next "random" number. Since the actual operation is known, given a specific value, you can predict the following value. However, given the initial value of arbitration, the numbers have a good distribution - these are "pseudo-random" numbers.

To save Rnd()from the beginning to the predicted number (and therefore to indicate the same sequence of "random" numbers each time), Randomize () should be called to use the machine clock to set the initial value (called a seed).

(In the .NET world, I would use System.Random if you can.)

+8

Randomize() Rnd(). - VB.NET .

+4

, , . , Rand() , . , System.Random VisualBasic Rand(). randomize()

, :

Dim randObj As New Random( seed )
Dim j As Integer
For j = 0 To 5
    Console.Write( "{0,11} ", randObj.Next( lower, upper ) )
Next j
Console.WriteLine( )
+1

Source: https://habr.com/ru/post/1716932/


All Articles