From: Omar Polo <op@omarpolo.com>
To: Emanuel Berg <moasenwood@zoho.eu>
Cc: help-gnu-emacs@gnu.org, emacs-devel@gnu.org
Subject: Re: urandom number in Emacs
Date: Sun, 07 Nov 2021 09:22:10 +0100 [thread overview]
Message-ID: <87sfw8s6zt.fsf@omarpolo.com> (raw)
In-Reply-To: <87bl2woma5.fsf@zoho.eu>
Emanuel Berg via "Emacs development discussions." <emacs-devel@gnu.org> writes:
>> This is a dynamic module with a function that reads from
>> /dev/urandom ... so more random numbers with
>> `random-urandom' than with `random' (since Lisp cannot read
>> from /dev/urandom because it's a non-regular file - IIUC?) -
>> so instead this uses the same C as in pwgen(1) to do it,
>> pretty simple I guess :P
>>
>> So now one can do (random-urandom) ... like any other Lisp
>> function and be on everyone else's level. Only cooler B)
>>
>> See a very long discussion on gmane.emacs.help ...
>>
>> Anyway, one C file, one C header file, and one Makefile
>> here:
>>
>> https://dataswamp.org/~incal/emacs-init/random-urandom/
>>
>> Just do 'make run'.
>
> ... Hello?
>
> Information theory guys? Practical guys writing it in Lisp?
> Portable and without any external tools? Why, don't run away
> all of a sudden?
>
> Can anyone hear me?
>
> I mean _this_ time around?
I mean, if you really need something like that and emacs doesn't already
provide it, why don't try cooking a diff to add it to base emacs instead
that an external module?
Also, the code is wrong:
> if (nbytes == 0) {
> return (rnd_num % max_num);
> } else {
> fprintf(stderr, "No entropy available!\n");
> exit(1);
> }
I don't think you want to quit emacs unconditionally if there's no
entropy.
Also, in some circumstances there could be better (and faster) ways to
obtain a random number, see for e.g. arc4random.
Cheers,
Omar Polo
P.S.: are you sure about checking for EAGAIN? A read for a file
descriptor not marked as non-blocking shouldn't fail with EAGAIN, but
that's a minor nitpick.
next prev parent reply other threads:[~2021-11-07 8:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-06 16:35 urandom number in Emacs Emanuel Berg via Emacs development discussions.
2021-11-07 0:13 ` Emanuel Berg via Emacs development discussions.
2021-11-07 8:22 ` Omar Polo [this message]
2021-11-07 8:49 ` Emanuel Berg via Emacs development discussions.
2021-11-07 8:53 ` Omar Polo
2021-11-07 9:28 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-07 8:58 ` Emanuel Berg via Emacs development discussions.
2021-11-07 19:47 ` Emanuel Berg via Emacs development discussions.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sfw8s6zt.fsf@omarpolo.com \
--to=op@omarpolo.com \
--cc=emacs-devel@gnu.org \
--cc=help-gnu-emacs@gnu.org \
--cc=moasenwood@zoho.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).