import random
# print a random integer number between 1 - 2 The stop number is not includedprint(random.randrange(start=1, stop=3))# print a random integer number between 1 - 2 The stop number is includedprint(random.randint(1,2))# print a random float number between two numbers the end number is also included in the random selectionprint(random.uniform(1,2))# generates random bits - print a random 8 bit integerprint(random.getrandbits(8))# print a random choice from an iterable object# prints 1, 2 or 3print(random.choice([1,2,3]))# prints a, b or cprint(random.choice('abc'))# print random choices from an iterable object# population is the iterable object. weights if for the possibility of outcome, k is for how many items to returns# weights and k arguments are optional# print a list of 10 heads or tails with an equal chance that it will be heads or tailsprint(random.choices(population=["heads","tails"], weights=[.5,.5], k=10))# print a list of 10 heads or tails with a more likely chance of tails chance that it will be heads or tailsprint(random.choices(population=["heads","tails"], weights=[2,10], k=10))# stuff a list and print the list in shuffled ordered
mylist =[1,2,3]
random.shuffle(mylist)print(mylist)# return a random sample of an iterable - k is the number of the sample to return# print two random characters from a string abcprint(random.sample(population="abc", k=2))# print 3 random list items from a listprint(random.sample(population=[1,2,3,4], k=3))# print a random number float between two numbers the mode allows a higher possible toward either the low or high value# the mode in this example will print a random float more closes to the high value of 50print(random.triangular(low=10, high=50, mode=40))
import random
print(random.randint(3,7))#Prints a random number between 3 and 7
array =[cars, bananas, jet]print(random.choice(array))#Prints one of the values in the array at random
# imports randomimport random
# randint generates a random integar between the first parameter and the secondprint(random.randint(1,100))# random generates a random real number in the interval [0, 1)print(random.random())
#import random import random
names =['Harry','John','Smith','Larry']#print random name from namesprint(random.choice(names))#print random integer in a range of numbersprint(random.randint(1,100)
import random
random.seed(1)# Get the state of the generator
state = random.getstate()print('Generating a random sequence of 3 integers...')for i inrange(3):print(random.randint(1,1000))# Restore the state to a point before the sequence was generated
random.setstate(state)print('Generating the same identical sequence of 3 integers...')for i inrange(3):print(random.randint(1,1000))
import random
print(random.randint(15,30))#Prints a number from 15 to 30 after picking a random number from 15 to 30
RandomNumber = random.randint(0,100)print(RandomNumber)
# I know somebody else has made a similar thing from mine.# Just letting you know that I didn't mean to copy his idea for this code.# If you saw this, I recommend check the other answers out, too.# Hope you guys understand...from random import randint
# Prints a random number in between 1 and 1000print(f"Here is a random number: {randint(1,1000)}")