import random # get seed from a user choice = input("Enter an integer seed (or 'r' to pick randomly): ") # as long as the input is not all digits or "r" # get the input again from the user while(choice.lower() != "r" and not choice.isdigit()): choice= input("Invalid input. Enter an integer seed (or 'r' to pick randomly): ") print(choice) # The method seed() of the random module # sets the integer starting value used in generating random numbers. # seed(x) # x -- This is the seed for the next random number. # If omitted, then it takes system time # to generate next random number. # This method does not return any value. # This function is not accessible directly, # so we need to "import random" and then call the seed function through it # example # random.seed(10) # print("Random number with seed 10 : ", random.random()) # # if user supplied a seed if choice.isdigit(): random.seed(int(choice)) print("Random number with seed", choice, ": ", random.random()) # let's see other examples for random number print("Random number with randrange : ", random.randrange(1, 10)) print("Random number with randint : ", random.randint(20, 30))