VB Problem I want to generate a set of random numbers, but I want to generate random numbers that do

Updated on technology 2024-04-13
6 answers
  1. Anonymous users2024-02-07

    I don't understand how to use recursion in your program**, if you just don't let the string with 4 be generated, use a condition.

    Plus a turn statement can be regenerated.

    public sub xunhuang()

    strtemp2 = string(val(, "0")

    r:strtemp = int(rnd * val("1" & strtemp2))

    for i = 1 to len(strtemp)

    if mid(strtemp, i, 1) = "4" then goto r

    nextend sub

    In addition, to find out if a string contains another character, it will be easier to use instr, ** as follows.

    public sub xunhuang()

    strtemp2 = string(val(, "0")

    dostrtemp = int(rnd * val("1" & strtemp2))

    loop until instr(strtemp, "4") =0

    end sub

  2. Anonymous users2024-02-06

    I don't know where your problem is**, which step can't be achieved means that it can't be achieved?

    I guess it's the call xunhuan statement followed by the exit sub

    Furthermore. It is best to initialize with randomize before generating random numbers.

    Determine if there are 4 with this simple point if instr(cstr(strtemp),"4"Then call xunhuang, so that you don't have to loop.

  3. Anonymous users2024-02-05

    1. Open the "Microsoft Visual Basic Chinese" software and prepare a blank project file

    2. Then you need a command button, click the "Command Button" in the toolbox on the left, and drag the left mouse button on the right side of the form to draw

    3. Double-click the command button, here is the demonstration of entering ** print any integer between 0 and 10, and generate a random integer formula for other ranges as "int((upper limit - lower limit + 1) * rnd + lower limit)", if it is 1 to 53 is "int((1-53 + 1) * rnd+53":

    4. After writing, run the program, and every time you click the command button, you will print an integer between 0 and 10 on the form

  4. Anonymous users2024-02-04

    The first way: use the parameterless random() constructor;

    The default seed value is used as the seed value, and if the random function is triggered for a short interval, it is possible to produce the same random number.

    The second way: use rngcryptoserviceprovider to generate seed values; Slower builds.

    1、random()

    Initialize a new instance of the random class with the default time-dependent seed value.

    2、random(int32)

    Initializes a new instance of the random class with the specified seed value.

    The parameter is a seed value with a data type of int32, which is used to calculate the number of the starting value of a pseudorandom sequence. If a negative number is specified, its absolute value is used.

    The random number generated by the random class is a pseudo-random number, so there is still a certain rule in the internal generation mechanism of random, and it is not completely random in the true sense. If the seed values are the same, the same random number is produced every time.

  5. Anonymous users2024-02-03

    Must be copied to initialize: randomize. There are no seeds. The data that comes out is definitely fixed.

    Example of a randomize statement.

    In this example, the randomize number generator is initialized with a randomize statement. Since the numeric argument is ignored, randomize uses the return value of the timer function as the new random number seed value.

    dim myvalue

    randomize 'The action of initializing the random number generator.

    myvalue = int((6 * rnd) +1) 'Generate a random value between 1 and 6.

  6. Anonymous users2024-02-02

    'Need to use it first.

    randomize 'The action of initializing the random number generator.

    But it can not be saved absolutely not repeated.

    What you said should be limited each time, the number produced is ranged, the number of numbers is limited, according to the drawer principle, there is always a time to repeat.

    Unless ......

Related questions
4 answers2024-04-13

Create a new project with two forms: form1, form2

There are two controls on form1: command button command1 and timer1There are two controls on form2: label label1 and timer1 click the command button when the program is running, the command button disappears, wait for 1 second and then pop up form 2 display: >>>More

9 answers2024-04-13

The decimal part of the date variable with a value of less than 1 corresponds to the time of day from 0:00:00 to 24:00:00 >>>More

3 answers2024-04-13

Your first one is not a loop statement.

private sub form_click()if i = 0 then >>>More

5 answers2024-04-13

mid(string a, start looking for the bit value (data b), find the number of digits (data c)) Your function looks like this. >>>More

14 answers2024-04-13

It's pretty big, but if you're a beginner, it's nothing, and it's going to change quickly at the beginning.