[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: urandom number in Emacs

From: Omar Polo
Subject: Re: urandom number in Emacs
Date: Sun, 07 Nov 2021 09:22:10 +0100
User-agent: mu4e 1.6.9; emacs 29.0.50

Emanuel Berg via "Emacs development discussions." <> 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 ...
>> Anyway, one C file, one C header file, and one Makefile
>> here:
>> 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

Also, in some circumstances there could be better (and faster) ways to
obtain a random number, see for e.g. arc4random.


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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]