Write a Python program to generate random even integers in a specific numerical range


The program uses the random module in Python to generate 10 random even numbers between 2 and 100 (inclusive).

  • random.randrange(2, 100, 2) generates a random integer between 2 and 100 (exclusive) with a step of 2.
  • range(10) generates a sequence of integers from 0 to 9, which are used in the loop to iterate 10 times.
  • The for loop is used to repeat the process of generating a random even number and printing it 10 times.

So, each time the loop runs, it generates a new random even number between 2 and 100 (inclusive) and prints it to the console.

Source Code

import random
for x in range(10):
	res = random.randrange(2, 100, 2)
	print(res)

Output

90
4
40
30
78
20
36
62
16
72

Example Programs