-
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
-
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.
-
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
-
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.
-
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.
-
'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 ......
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
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
Your first one is not a loop statement.
private sub form_click()if i = 0 then >>>More
mid(string a, start looking for the bit value (data b), find the number of digits (data c)) Your function looks like this. >>>More
It's pretty big, but if you're a beginner, it's nothing, and it's going to change quickly at the beginning.