unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Generate random char (and string) from unicode category (e.g: letter)
@ 2018-12-06 10:44 Alexandre Garreau
  2018-12-06 11:24 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Alexandre Garreau @ 2018-12-06 10:44 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I recall clearly having wrote in elisp something to generate random and
more-or-less plausible input for gmail account creation form, including
ascii chars for login, statistical randomness for gender (like, iirc,
48% of “male”, 52% of “female”, minus 2% of “others”), and random
unicode for password, real name, etc. I recall in the end I ended with a
lot of ideograms in those.  So I know it’s doable in pure elisp (or
maybe was it guile? less likely…).

I really don’t recall how I did that, nor if I took care of using a
single script for each form input, but I’m sure I was using something
less ugly than currently, that is, (random (max-char)) until it matches
[[:alpha:]] (but I clearly recall using something that would work for
all unicode, including foreign scripts I wouldn’t even know about).

Do you have an idea of something cleaner? currently I have this:

#+BEGIN_SRC emacs-lisp
(defun random-letter (&rest osef)
  (let ((num (random (max-char))))
    (until (string-match "[[:alpha:]]" (string num))
      (setq num (random (max-char))))
    num))
#+END_SRC

and use it like this:

#+BEGIN_SRC emacs-lisp
(apply #'string (mapcar #'random-letter (make-list (1+ (random 190)) nil)))
#+END_SRC

Problems is I get stuff like this: "䯩繩ꏴ跾ಾ𢉰𐎕𘓅𪆶矏ᄬ𣒈⳰𨜄𛰸𧅌煂𢙴𧐁𡚯
𦅉ᤋ𡇼钇꿚㱓㗧𩅍姵爠𣑽𠌤ꇊ𡘄𑄇𫲘𪯋𣊚𦉂𠦵𘕋𠈾ლ𨟇𦷕𤃻𫿡𢿟巙𩿊𥖠𒒈ባ𗆘𤧟𗲀𔗸𖼂뺔
𧸋𡠜𬶟咨발𬞗쏊紋䲁坮𠢥旼𗴟𬓏𤁍គ𩍏Ɉ𪅊𤙬𫪃𫴛𤶋𫴃𧐨䞪𩇨𡤦馲𨂧𡮃𓂅𒇵𤉴𥙯藣ბ솇
𨆬𦄎靔𐤒ඐ𒐕襋𬵝𥤄𪃝𫈹𨣼𘋹돃𪣞筛𣯿휈𥽊Ꭾ𣐧𥺒𠊆ꮩ闭ઉ𦻸𨔆𤛢𢮁𤟩𪊕𥫰𪢟𡻋𘅇ᶗ펙𣄽
玽쭻𩿎𗔥𪟉䪁ᣃ쒝𩅑𡞬넒煮ڒꫥ𥾴𣁫𬑼깙𣫖筁ᣯ𣱮𡡯𨐒ﶒ𤑳𤯼昵䊘㝓𣑼𐦥𥆤갛𤡇𠜠𥉡䋯𥫻
𪲩兀𖠹瀖𣊫𨘥𢍪ᴢ", where the majority of characters are non-displayable
and are shown with a square with numbers in it to indicate there’s
nothing such that in installed fonts.  I clearly recall I what I did
there were no such characters, so something must be possible (maybe
using charsets?).

PS: is there a way to get something else than linear random distribution
with `random'? like normal law, or logarithmic distribution?

^ permalink raw reply	[flat|nested] 4+ messages in thread
[parent not found: <mailman.5272.1544093503.1284.help-gnu-emacs@gnu.org>]

end of thread, other threads:[~2018-12-06 14:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-06 10:44 Generate random char (and string) from unicode category (e.g: letter) Alexandre Garreau
2018-12-06 11:24 ` Eli Zaretskii
     [not found] <mailman.5272.1544093503.1284.help-gnu-emacs@gnu.org>
2018-12-06 13:46 ` Ben Bacarisse
2018-12-06 14:29   ` Emanuel Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).