Home > Net >  python program to get n unique sequence number within a range
python program to get n unique sequence number within a range

Time:03-04

the input is the range and total number needed.

consider input range is (0,1)

if the total number needed is 10.Then output should be an array containing 10 values between 0 to 1. including 0 and 1.

if the total number needed is 5.Then output should be an array containing 5 values between 0 to 1. including 0 and 1.

CodePudding user response:

This is an Arithmetic Progression problem.
Using the formula
Tn = a (i-1) * d
b = a (n-1) * d

# input range
a = 0
b = 1
# total number needed
n = 5

d = (b-a)/(n-1)
arr = [a (i-1)*d for i in range(1, n 1)]

print(arr)
  • Related