Answers for "random list python"

13

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]
Posted by: Guest on March-02-2020
5

random from list python

import random

foo = ['a', 'b', 'c', 'd', 'e']
print(random.choice(foo))
Posted by: Guest on March-29-2021
10

python function to print random number

import random
n = random.randint(0,22)
print(n)
Posted by: Guest on June-03-2020
3

n random numbers python

>>> import random
>>> random.sample(range(1, 100), 3)
[77, 52, 45]
Posted by: Guest on October-27-2020
1

python randomly sample entry from a set

# Basic syntax:
import random
random.sample(your_set, number_of_elements)
# Where:
#	- number_of_elements is the number of elements you want to sample
# 		without replacement from your_set
# Note, the samples elements are returned as a list. Use set(the_list)
#	to convert back to a set

# Example usage:
your_set = {'a', 'bunch', 'of', 'unique', 'words'}
random.sample(your_set, 1)
--> ['words']

random.sample(your_set, 3)
--> ['words', 'of', 'a']
Posted by: Guest on November-17-2020
0

random list python

import random
#random numbers 0-9 in a list of length 10
array = [random.randint(0,9) for i in range(10)]
print(array)
Posted by: Guest on November-16-2021

Python Answers by Framework

Browse Popular Code Answers by Language