VBA/Excel/Access/Word/Math Functions/Rnd

Материал из VB Эксперт
Перейти к: навигация, поиск

Rnd([number]) returns A random number (with no argument) or a number based on the given initial seed.

   <source lang="vb">

Sub mathDemo10()

  Debug.Print Rnd(1)
</source>
   
  


==Rnd() Returns a random number between 0 and/td>




   <source lang="vb">

Sub mathF6()

   Debug.Print Rnd()

End Sub

</source>
   
  


To prevent repetitive sequences, use the Randomize statement to initialize the random number generator with a seed value based on the system clock.

   <source lang="vb">

Sub intDemo()

   Dim val1
   Randomize
   val1 = Int(100 * Rnd + 1)

End Sub

</source>