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
6 Answers
+ 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
+ 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
+ 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)
+ 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.
+ 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)
+ 1
Oh wow that helps immensely thank you, my original intention putting the int in str was to prevent a concatenation error