Home > Article > Backend Development > How to use random function in C language
C language random function usage: 1. random.random, randomly generates a floating point number between (0,1); 2. random.randint, randomly generates an integer within the range, the two parameters are respectively Indicates the upper and lower limits; 3. random.randrange, within the specified range, obtain a random number from a set incrementing by the specified base; 4. random.choice, randomly select a number from the sequence; 5. random.shuffle, randomly Sort.
Usage:
1, random.random()
Randomly generate a float between (0,1) Points
2, random.randint(upper limit, lower limit)
Randomly generate an integer within the range, the two parameters represent the upper limit and lower limit respectively
3, random. randrange( , , )
Obtains a random number from the set incrementing by the specified base within the specified range. It has three parameters. The first two parameters represent the upper and lower limits of the range, and the third parameter is the increment. , excluding the lower limit, including the upper limit
The usage method is as follows:
random.randrange(0,11,2)
Randomly generate numbers with a range of 10 and an interval of 2
Note: Output here is one
4 in (0,2,4,6,8,10), random.choice(list)
is randomly selected from the sequence A number
5, random.shuffle(list)
Random sorting
Note: list elements are numeric
The above is the detailed content of How to use random function in C language. For more information, please follow other related articles on the PHP Chinese website!