Linked Questions

22 votes
2 answers
38k views

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....
user3258159's user avatar
0 votes
3 answers
3k views

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, ...
Lili's user avatar
  • 9
0 votes
1 answer
772 views

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 ...
Cooper's user avatar
  • 45
0 votes
3 answers
699 views

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 ...
Quinton Van vuuren's user avatar
-5 votes
2 answers
781 views

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 ...
Nexus's user avatar
  • 21
0 votes
0 answers
256 views

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 ...
djmcg's user avatar
  • 11
0 votes
1 answer
121 views

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("...
Brayden Senter's user avatar
0 votes
1 answer
101 views

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 ...
Safe G's user avatar
  • 3
-1 votes
1 answer
176 views

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 ...
m.n.m's user avatar
  • 21
0 votes
3 answers
80 views

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 ...
new_programmer_python's user avatar
0 votes
2 answers
85 views

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 ...
Rahn's user avatar
  • 5,565
0 votes
1 answer
39 views

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 ...
lolgamer719's user avatar
203 votes
21 answers
419k views

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?
iCodeLikeImDrunk's user avatar
171 votes
10 answers
356k views

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....
Gabriel's user avatar
  • 43k
74 votes
4 answers
163k views

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-...
Stiggo's user avatar
  • 1,047

15 30 50 per page