Linked Questions
43 questions linked to/from Generate 'n' unique random numbers within a range
22 votes
2 answers
38k views
Generate three different random numbers [duplicate]
I've got something here, but I can't get it working how I like it: def nested_loops(): import random option1 = random.randint(1, 3) option2 = random.randint(1, 3) option3 = random....
0 votes
3 answers
3k views
How do I generate multiple *different* random numbers? [duplicate]
I'm trying to create a code that produces a list of 5 different random number. Here is my current code: import random rN0 = random.randint(1, 50) rN1 = random.randint(1, 50) rN2 = random.randint(1, ...
0 votes
1 answer
772 views
How to disable Python program from printing same value in list more than once? [duplicate]
So I have a program that randomly selects a certain amount of items from a list, but if a value is randomly selected I would like it to only print once, and make the program unable to print the same ...
0 votes
3 answers
699 views
I have to generate random integers in python, but the user has to say how many integers they want to generate [duplicate]
I have to ask the user how many numbers they want to generate and then i can generate integers according to them in the range of 0 to a 100. If the user wants 5 numbers I have to generate 5 random ...
-5 votes
2 answers
781 views
How would I generate a random sequence of numbers without going accidently going over the same numbers? [duplicate]
This is probably a duplicate of something, but oh well. I'm trying to create a random number generator that goes over all 7 digit numbers (0000001 - 9999999) but I'm having issues thinking how I'd ...
0 votes
0 answers
256 views
Python - How to use random without repeating the previous value [duplicate]
Could You advice how to update code without repeating the previous value. import random import time while True : a=(random.randint(1,5)) #print("Number = "+str(a)) time.sleep(0.8) if ...
0 votes
1 answer
121 views
Python: How to prevent a randomly generated number from appearing twice [duplicate]
import random import time import sys x = input("Put a number between 1 and 100: ") z = int(x) if z < (0): sys.exit("Number too small") if z > (100): sys.exit("...
0 votes
1 answer
101 views
How can I replace a integer that shows up twice in a random list [duplicate]
I have a list that looks like this: l = [random.randint(0,9),random.randint(0,9),random.randint(0,9),random.randint(0,9)] but if it outputs something like this[9,0,5,5] what can I do replace the ...
-1 votes
1 answer
176 views
Generate random sequence of letters of length K from list of letters [duplicate]
I am trying to write a function that generates a random sequence of letters (letters from a list), and the sequence length is K (K is passed to the function as an argument when function is called). I ...
0 votes
3 answers
80 views
Making a random int just be itself once in loop [duplicate]
So.. im working on this loop: stuff_so_far = [intl_pt] for i in range(0, num_pts - 1): rdm = random.randint(0, len(points_in_code) - 1) a = (stuff_so_far[i][0] + points_in_code[rdm][0]) // 2 ...
0 votes
2 answers
85 views
Delay the evaluation of list items [duplicate]
I want to generate a list of random integer within a range: from random import randint lower = 0 upper = 20 length = 10 random_array = [randint(lower, upper) for _ in range(length)] I don't think ...
0 votes
1 answer
39 views
random nr gen python (title isnt working constantly) [duplicate]
So I am pretty new to Python and to coding in general and I am trying to make a random number generator which makes a list of what numbers havent been displayed yet and doesnt repeat any of the ...
203 votes
21 answers
419k views
How do I create a list of random numbers without duplicates?
I tried using random.randint(0, 100), but some numbers were the same. Is there a method/module to create a list unique random numbers?
171 votes
10 answers
356k views
Generate random array of floats between a range
I haven't been able to find a function to generate an array of random floats of a given length between a certain range. I've looked at Random sampling but no function seems to do what I need. random....
74 votes
4 answers
163k views
Create random list of integers in Python
I'd like to create a random list of integers for testing purposes. The distribution of the numbers is not important. The only thing that is counting is time. I know generating random numbers is a time-...