0

# How do you make randint select 25 entries

Im trying to make a bingo card generator, I have it programmed to print random values up to 75 with their letter, but I want it to select 25 unique values and sort them in a 5Ã—5 matrix

30th Nov 2022, 6:16 PM
Tyler Page
+ 2
Not sure why you want to cast the int into str. But here I tried to do what your code suggests â€“ associate 5 int as str to each of the letter depending on their values. https://code.sololearn.com/cmKR44XB82b5/?ref=app
30th Nov 2022, 8:28 PM
Lochard
+ 5
Using random.sample() inbuilt method of the random module which takes the sequence and number of selections as arguments and returns a particular length list of items chosen from the sequence i.e. list, tuple, string or set. It is used for random selection from a list of items without any replacement. https://code.sololearn.com/cocmZpsj17DO/?ref=app
30th Nov 2022, 6:52 PM
JaScript
+ 3
Like this it can be done, add the values to a set until you have 25 entries: from random import randint s = set() x = 0 while x < 25: y = randint(1,75) s.add(y) x = len(s) l = list(s) print (l)
30th Nov 2022, 6:37 PM
Paul
+ 3
Tyler Page , When you want to divide numer ranges on letters then this can be done without if statements only with one set for each letter and randint of this range.
30th Nov 2022, 8:11 PM
JaScript
+ 1
This is what I have so far, still struggling to make it print the full list of 25, this is my first week of learning so I really appreciate the help (edit, just fixed it the indentation on print(l) was off) Now to arrange them into 5 rows of 5 from random import randint s = set() i = 0 while i < 25: x = randint(1,75) s.add(x) l = list(s) if x<=15: l=["B"+str(x)] elif x<=30: l=["I"+str(x)] elif x<=45: l=["N"+str(x)] elif x<=60: l=["G"+str(x)] else: l=["O"+str(x)] i+=1 print (l)
30th Nov 2022, 6:57 PM
Tyler Page
+ 1
Oh wow that helps immensely thank you, my original intention putting the int in str was to prevent a concatenation error
30th Nov 2022, 9:34 PM
Tyler Page