python generate a list of random number code example

Example 1: python list of random values

# To create a list of random integer values:
import random
randomlist = random.sample(range(10, 30), 5)
# Output:
# [16, 19, 13, 18, 15]

# To create a list of random float numbers:
import numpy
random_float_array = numpy.random.uniform(75.5, 125.5, 2)
# Output:
# [107.50697835, 123.84889979]

Example 2: random python code

# Here is a literal random python code:
numbers = []

def while_loop(i, x, y):
    
    while i < x:
        print(f"At the top i is {i}")
        numbers.append(i)

        i = i + y
        print("Numbers now: ", numbers)
        print(f"At the bottom i is {i}")
    
    print("The numbers: ")

    for num in numbers:
        print(num)

while_loop(0, 6, 1) 
# The last number is an incrementor, which specifies how much the variable "i" goes up by.