+ 7

How can I print random numbers or charecters to the screen ?

hi everyone! I had a simple doubt with you. how can I print random numbers or charecters to the screen ? I even searched in Google but I could not understand it . any help would be greatly appreciated. thank you!

7th Aug 2019, 12:34 PM
sujay simha
sujay simha - avatar
10 Réponses
+ 8
7th Aug 2019, 1:11 PM
sujay simha
sujay simha - avatar
+ 6
Thanks ~ swim ~
7th Aug 2019, 12:47 PM
sujay simha
sujay simha - avatar
+ 6
Thanks a lot Jordi de Pelseneer
11th Aug 2019, 4:30 PM
sujay simha
sujay simha - avatar
+ 5
I think I forgot that it was there
7th Aug 2019, 12:48 PM
sujay simha
sujay simha - avatar
+ 5
Anyway thanks
7th Aug 2019, 12:48 PM
sujay simha
sujay simha - avatar
+ 5
but how can I do it if I want to provide the numbers or charecters ?
7th Aug 2019, 1:03 PM
sujay simha
sujay simha - avatar
+ 3
For example you can use random.randint in combination with the built-in function chr(). First you look up the ASCII table on the www, then you figure out which numbers the letters you want have. And then you generate an int with randint using your range of letters as the borders of the range, and you transform the result into a letter with chr. There are other ways as well. Use Google with what I said, try to figure it out, you'll make it. 😉
7th Aug 2019, 1:09 PM
HonFu
HonFu - avatar
+ 1
if i understand your question correctly. u need to import the 'random' librairy. Easy way to print random numbers, i using a for loop for example; for i in range(1): print(random.randint(1,100) this will print a random number between 1 and 100. For random Characters, you can use ASCII, or just make a list with all the letters in it and loop trough it randomly.
11th Aug 2019, 2:58 PM
Jordi
Jordi - avatar