Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Python randomly generates random numbers in [0, 100], finds the maximum and minimum values, and exchanges positions.
Python randomly generates random numbers in [0, 100], finds the maximum and minimum values, and exchanges positions.
The process is as shown in the figure:

There are two ways to obtain random numbers in the range of 1~ 100:

Method 1: You can get the random number through the random method in math class, multiply it by 100 plus 1, and then convert it into int type.

Method 2: You can get the Random number through the nextInt method in the random class.

Extended data

Supplementary explanation of function use

1 and random are used to generate random numbers, and can be used to randomly generate numbers or select strings.

Random.random () is used to generate a random floating-point number: range[0.0, 1.0].

Random.uniform(a, b) is used to generate random floating-point numbers within a specified range, where a and b are upper and lower bounds, as long as a! =b, a floating-point number between the two will be generated. If a=b, the generated floating-point number is A..

Random.randint(a, b) is used to generate integers within a specified range, where a is the lower limit and b is the upper limit, and the generated random integer A < = n < = b; If a=b, then n = a;; If a>b reports an error.

Random. Rand range ([start], stop [,step]), from the specified range, get a random number from the set increasing by the specified radix, and the default value of radix is 1.

Random.choice(sequence), a random element is obtained from the sequence, and the parameter sequence represents an ordered type, not a specific type, generally referring to list, tuple, string, etc.

Random.shuffle(x[, random]), which is used to scramble the elements in the list.

Random.sample(sequence, k), which randomly obtains k elements from the specified sequence and returns them as fragments. The sample function does not modify the original sequence.

2. There are two functions in 2.Python: join () and os.path.join (). The specific functions are as follows:

Join (): An array of connection strings. Concatenates strings, tuples, and elements in the list with the specified character (delimiter) to generate a new string.

Os.path.join (): Combine multiple paths and return.