Home >Common Problem >Usage of Rnd function in VB
Usage of Rnd function in VB
Rnd is a function that can generate double-precision random numbers between [0,1). int(N) is a function that takes the largest integer less than or equal to N, such as int(4.5)=4, int(-4.5)=5.
int(rnd usage method:
int(rnd * 范围 + 基数)
For example: int(rnd*m n) means to generate a random number between [n,m n-1]
Example: Suppose you want to store 6 randomly generated integers between 40 and 60 (including 40 and 60) into a one-dimensional array suijishu(). The statement is:
dim suijishu(1 to 6) as integer, i as integer for i = 1 to 6 suijishu(i)=int(rnd*21+40) next i
Analysis:
0<=rnd<1
0<=rnd*21<21
40<=rnd*21 40<61
40<=int( rnd*21 40)<=60
For more tutorials, please visit php中文网.
The above is the detailed content of Usage of Rnd function in VB. For more information, please follow other related articles on the PHP Chinese website!