57 of 151 menu

The uniform method of the random module

The uniform method of the random module returns a pseudo-random real number from a given range. In the first parameter of the method, we specify the initial value of the range, in the second - the final value.

Syntax

import random random.uniform(beginning, end)

Example

Let's generate a number in the range from 0 to 10:

print(random.uniform(0, 10))

Result of code execution:

4.840831811035069

Example

Now let's generate a number in the range of negative numbers:

print(random.uniform(-4, -1))

Result of code execution:

-3.2516379041520467

See also

  • method random of module random,
    which returns a pseudo-random number
  • method seed of module random,
    which initializes a random number
  • method randint of module random,
    which generates a pseudo-random integer from a range
  • method randrange of module random,
    which returns a random number from a range
byenru