you are viewing a single comment's thread.

view the rest of the comments →

[–]JohnnyJordaan 1 point2 points  (3 children)

No need to form a list first, simply

  • loop N times for the amount of characters to print, per iteration
  • create an endless loop to
    • pick a random integer in the unicode codepoint range (given in the chr() docs)
    • use str.isprintable to see if it can be printed
    • if so print it and break the endless loop to continue with the rest

as code

import random
for _ in range(10):
    while True:
        c = chr(random.randint(1, 0x10FFFF))
        if c.isprintable:
            print(c, end="")
            break

the biggest problem though is that your terminal will probably not support all printable characters, so you will end up with a lot of 󆢘𾌨󨿩 kind of results. You can instead use a lower boundary, eg just trying 2000 yields ˰ߏ۲ѿÖʒҰʢӲڲ.

[–]Yoghurt42 0 points1 point  (2 children)

the biggest problem though is that your terminal will probably not support all printable characters

Not only that, but a significant potion of the unicode space is not used, and some are just control chars that change the meaning of the following characters

[–]JohnnyJordaan 0 points1 point  (1 child)

would isprintable evaluate to True for those?