Generate a string of random unicode letters (slow).
(n, seed=42)
| 68 | |
| 69 | |
| 70 | def _random_unicode_letters(n, seed=42): |
| 71 | """ |
| 72 | Generate a string of random unicode letters (slow). |
| 73 | """ |
| 74 | def _get_more_candidates(): |
| 75 | return rnd.randint(0, sys.maxunicode, size=n).tolist() |
| 76 | |
| 77 | rnd = np.random.RandomState(seed) |
| 78 | out = [] |
| 79 | candidates = [] |
| 80 | |
| 81 | while len(out) < n: |
| 82 | if not candidates: |
| 83 | candidates = _get_more_candidates() |
| 84 | ch = chr(candidates.pop()) |
| 85 | # XXX Do we actually care that the code points are valid? |
| 86 | if unicodedata.category(ch)[0] == 'L': |
| 87 | out.append(ch) |
| 88 | return out |
| 89 | |
| 90 | |
| 91 | _1024_random_unicode_letters = _random_unicode_letters(1024) |
no test coverage detected