Doubt! How did VB s formula for generating random integers come about?

Updated on technology 2024-05-27
4 answers
  1. Anonymous users2024-02-11

    upperbound and lowerbound represent the upper and lower bounds of a range, respectively, which is custom and can be changed.

    upperbound - lowerbound represents the size of this range, and each number generated is contained in upperbound - lowerbound, but the int function int is used to round down, so you must add 1 to ensure that the maximum value of upperbound will occur.

    Okay, now we have the maximum range (upperbound - lowerbound + 1), and then look at the random function rnd, this function can randomly appear any number between 0 and 1, so just use it to multiply it by the maximum range (upperbound - lowerbound + 1), you can have any number between 0 (upperbound - lowerbound + 1), plus lowerbound, This range becomes:

    lowerbound (upperbound + 1), but the number in this range is still a decimal, so use the function int to round it down, and you can generate a random integer in the lowerbound upperbound range.

  2. Anonymous users2024-02-10

    Let's say generate an integer between 5 and 10 with the formula:

    int(rnd *6)+5

    rnd generates decimals between 0 1, then rnd*6 = decimals between 0 6, but less than 6, so int(rnd*6) = an integer between 0 5, and then +5 = 5 10 integer.

  3. Anonymous users2024-02-09

    1. The formula for the random number that produces the interval [a,b] in vb is: int((b- a+ 1) *rnd + a).

    2. According to the above formula, it is impossible to generate random numbers in the range of (a, b] (half-open interval) by the formula method.

    3. The rnd function returns a value less than 1 but greater than or equal to 0.

    4. int is an integer function.

  4. Anonymous users2024-02-08

    The answer is a

    rnd returns a pure decimal in the range of [0,1), which can be taken as a value of 0, but not a value of 1, so the range of rnd*21 is [0,21), the range of rnd*21+30 is [30,51), and the range of int (rnd*21+30) is an integer between [30,50].

Related questions
3 answers2024-05-27

option explicit

private sub form_load()randomize >>>More

4 answers2024-05-27

You can take a look at the function description in excel and try a few more times. >>>More

6 answers2024-05-27

The generated file is located in the root directory of the D drive. >>>More

14 answers2024-05-27

dim x as long 'New.

get #1, ,r2 'Read the record of R2 from the first point in channel 1; get 1, 2, r2 read the 2nd record of r2 from inside channel 1. >>>More

13 answers2024-05-27

On the first floor, your method generates an array of controls that can't respond to events.